如何在多个Dropdownlist中显示相同的列字段 [英] How to display same column fields in multiple Dropdownlist
本文介绍了如何在多个Dropdownlist中显示相同的列字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所有
strQry = 从ShiftLite中选择CodeC;
DataTable dt2 = new DataTable();
dt2 = DbCon.GetData(strQry);
DropDownList1.DataSource = dt2;
DropDownList1.DataTextField = CodeC;
DropDownList1.DataBind();
DropDownList1.Items.Insert( 0 , new ListItem( - SELECT - , 跨度>));
这里我想要从数据库中检索的相同字段我想显示多个DropDlist如DropDownList2,DropDownList3,DropDownList4,DropDownList5
有没有办法轻松搞定
谢谢你!
解决方案
用4个args创建一个函数
PopulateDropDown(DropDownList ddl,DataTable dt, string displayField, string defaultText){
ddl.DataSource = dt;
ddl.DataTextField = displayField;
ddl.DataBind();
DropDownList1.Items.Insert( 0 , new ListItem(DefaultText, ));
}
我相信这个问题在这里得到解答。
http://stackoverflow.com/questions/16889407/binding-multiple-dropdownlists-to-the -same-datasource [ ^ ]
Hi, ALL
strQry = "select CodeC from ShiftLite";
DataTable dt2 = new DataTable();
dt2 = DbCon.GetData(strQry);
DropDownList1.DataSource = dt2;
DropDownList1.DataTextField = "CodeC";
DropDownList1.DataBind();
DropDownList1.Items.Insert(0,new ListItem("--SELECT--",""));
here i want same fields which i retrieve from database i want to display multiple dropdownlist like DropDownList2, DropDownList3,DropDownList4, DropDownList5
Is there any way to get easly
thanks you !
解决方案
Create one function with 4 args
PopulateDropDown(DropDownList ddl,DataTable dt,string displayField,string defaultText){ ddl.DataSource = dt; ddl.DataTextField = displayField; ddl.DataBind(); DropDownList1.Items.Insert(0,new ListItem(DefaultText,"")); }
I believe this question is answered here.
http://stackoverflow.com/questions/16889407/binding-multiple-dropdownlists-to-the-same-datasource[^]
这篇关于如何在多个Dropdownlist中显示相同的列字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文