Gridview数据显示从.cs页面手动 [英] Gridview Data Show Manually From .cs Page
本文介绍了Gridview数据显示从.cs页面手动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的aspx页面中有一个Gridview和一个下拉列表。我想设置/填充Gridview数据当我从下拉列表中选择一些东西(dropdownlist1.SelectIndexChanged事件)时,该怎么做?
i希望在代码隐藏文件(cs文件)中执行此操作。
提前谢谢
解决方案
dropdownlist.selectedchange 事件
{
string str = select * from table name其中Id = + dropdownlist.seletedvalue + ;
SqlCommand cmd = new SqlCommand(str,con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds );
gridview.datasource = ds.tables [0];
gridview.databind();
}
将Dropdownlist选择的值或文本传递给y我们的SQL查询。然后将结果数据集绑定到gridview。然后绑定gridview。
I have a Gridview and a Dropdown list in my aspx page. I want to set/fill the Gridview data When i select something from the dropdown list(dropdownlist1.SelectIndexChanged event), how to do it?
i want to do it in code behind file(cs file).
Thank you in advance
解决方案
inside the dropdownlist.selectedchange event { string str="select * from table name where Id="+dropdownlist.seletedvalue+"; SqlCommand cmd = new SqlCommand(str, con); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); gridview.datasource=ds.tables[0]; gridview.databind(); }
Pass the Dropdownlist selected value or text to your sql query. Then the bind the resulted dataset to your gridview. and then bind the gridview.
这篇关于Gridview数据显示从.cs页面手动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文