用于在gridview中显示数据的C#代码
问题描述:
我有一个表,其中包含字段供应商(字符类型)类别(字符类型)
我想将供应商作为request.query字符串,并且以此为基础,我想填充gridview.那么,它的C#代码是什么.
i have a table with fields supplier (char type ) catogory (type char)
i want to make supplier as request.query string and that bases i want to fill gridview .so what is c# code for it.
答
看看下面的代码是否对您有帮助:
See if below code helps you:
private string supplierName = string.Empty;
protected void Page_Load(object sender, EventArgs e)
{
supplierName = Convert.ToInt32(Request.QueryString["SupplierName"].ToString());
if (!IsPostBack)
{
BindGridView();
}
}
private void BindGridView()
{
con.Open();
SqlCommand cmd = new SqlCommand("SELECT * FROM tblCategory where SupplierName=" + supplierName , con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
con.Close();
DataSet ds = new DataSet();
da.Fill(ds);
gridview1.DataSource = ds;
gridview1.DataBind();
}