如何邦—ropDownList1
SqlCommand DBRS = new SqlCommand( "Select Trname from Tradmin ", conn);
SqlDataReader DB = DBRS.ExecuteReader();
DropDownList的id: DropDownList1
字段 Trname
[解决办法]
DropDownList1.DataSource=DB
DropDownList1.DataTextField=Trname;
DropDownList1.DataValueField=TrID;
DropDownList1.DataBind();
不过数据库源最好是DaTaTable,DataReader转换成Table就行了。
[解决办法]
ding ls
[解决办法]
vs2005中无需代码,直接拉控件过来用,然后他会提示让你选择数据源。
或者你在Design视图中选中你的DropDownList控件然后右击选择“smart tag”会出现一个菜单页面让你配置DropDownList的数据源。
[解决办法]
ListItem li = new ListItem(Trname,TrID);
this.DropDownList1.Items.Add(li);
[解决办法]
SqlCommand DBRS = new SqlCommand( "Select Trname from Tradmin ", conn);
SqlDataReader DB = DBRS.ExecuteReader();
字段 Trname
DropDownList的id: DropDownList1
DropDownList1.DataSource=DB
DropDownList1.DataTextField= "Trname "; 你的字段 呈现的
DropDownList1.DataValueField= "Trname ";你的字段 隐藏的
DropDownList1.DataBind();