开发者

Populate DropDownList from DataSource

I开发者_如何学编程 have an SQL Data Source which selects all rows of a table. I need to populate a dropdownlist with a certain field ('percentage') of all the rows, and when one is clicked to make the 'value' the rows 'id' field.

Is there a simple way of doing this? Thanks


You would want this:

<asp:DropDownList id="ddl_Items" runat="Server" DataTextField="percentage" 
     DataValueField="id" DataSourceId="sds_Items" />

<asp:SqlDataSource id="sds_Items" ...........other stuff........ />

You don't need to worry about assigning the value on click. Just do it when you load the DropDownList in the first place.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜