日期:2014-05-17  浏览次数:20428 次

关于DropdownList绑定
首先sql语句取出表中的所有列名已经实现

select name from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name='RJProduct') 

现在想把所有列明绑定到dropdpwnlst中,问题有一个,就是这个表中的列是不确定的是随时增加的,这个绑定怎么实现?求代码。

------解决方案--------------------
动态就动态呗,完全不影响啊,你取出的列名就是
select name from syscolumns where id=(select max(id) from sysobjects where xtype='u' and name='RJProduct') 
红色的部分。

绑定你指定是name字段就行了,里面多少个元素你不用考虑的

C# code

DataSet  ds  = XXX("你的SQL语句");
this.DropDownList1.DataSource = ds;
this.DropDownList1.DataTextField = "name";
this.DropDownList1.DataValueField = "name";
this.DropDownList1.DataBind();