开发者

Populate DropDownList from DataSource

开发者 https://www.devze.com 2023-01-20 15:46 出处:网络
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 t

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

精彩评论

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