如何将来自同一表的不同ID数据绑定到gridview [英] how to bind different ID data from same table into gridview
本文介绍了如何将来自同一表的不同ID数据绑定到gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个问题..我不知道如何将来自同一表的具有其ID的数据绑定到gridview中.
i have a problem.. i don''t know how to bind data that has its own ID from same table into a gridview.
SqlDataAdapter sqlcom0 = new SqlDataAdapter("select no_of_train from transshipment where id_transshipment =1", myConnection);
DataSet ds0 = new DataSet();
sqlcom0.Fill(ds0, "transshipment");
gd_transshipment.DataSource = ds0.Tables["transshipment"].DefaultView;
gd_transshipment.DataBind();
SqlDataAdapter sqlcom10 = new SqlDataAdapter("select no_of_train from transshipment where id_transshipment =2", myConnection);
DataSet ds10 = new DataSet();
sqlcom10.Fill(ds10, "transshipment");
gd_transshipment.DataSource = ds10.Tables["transshipment"].DefaultView;
gd_transshipment.DataBind();
当我运行网站时,结果将显示gridview的两列,其数据为id_transshipment = 2.
我希望它成为column1 =具有id_transshipment = 1的数据,然后column2 =具有id_transshipment = 2的数据
我真的希望有人能帮助我解决这个问题.
在此先感谢.
when i run the website, the result display the both columns of gridview with the data id_transshipment=2.
i want it to be column1 = data that has id_transshipment=1 then column2 = data that has id_transshipment=2
i really hope someone can help me to figure it out.
thanks in advance.
推荐答案
尝试一下,
Try this ,
SqlDataAdapter sqlcom0 = new SqlDataAdapter("select no_of_train from transshipment where id_transshipment in (1,2)", myConnection);
DataSet ds0 = new DataSet();
sqlcom0.Fill(ds0, "transshipment");
gd_transshipment.DataSource = ds0.Tables["transshipment"].DefaultView;
gd_transshipment.DataBind();
这篇关于如何将来自同一表的不同ID数据绑定到gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文