productList.aspx.cs

(完整代码) 1KB

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class productList : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string categoryID = Request.QueryString["categoryID"].Trim().ToString();
        SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["shopConnectionString"].ToString());
        conn.Open();
        SqlDataAdapter data = new SqlDataAdapter("select product.productname,product.originalprice,category.categoryname,product.saleprice,product.photo, productID from product,category where product.categoryID=category.categoryID and product.categoryID='"+categoryID+"'", conn);
        DataSet ds = new DataSet();
        data.Fill(ds);
        this.DataList1.DataSource = ds.Tables[0].DefaultView;
        this.DataList1.DataBind();

    }
    protected void DataList1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {

        DataRowView MyDataRowView = (DataRowView)e.Item.DataItem;
        ((Label)e.Item.FindControl("productname")).Text = MyDataRowView.Row[0].ToString();
        ((Label)e.Item.FindControl("categoryname")).Text = MyDataRowView.Row[2].ToString();
        ((Label)e.Item.FindControl("originalprice")).Text = MyDataRowView.Row[1].ToString();
        ((Label)e.Item.FindControl("saleprice")).Text = MyDataRowView.Row[3].ToString();
        ((Image)e.Item.FindControl("photo")).ImageUrl = "images\\"+MyDataRowView.Row[4].ToString();
        ((Image)e.Item.FindControl("detial")).ImageUrl= "images\\detail.gif";
    }
    
}

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读 AI

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。