Populating a DropDownList from a DataSource

I have an SQL data source that selects all the rows of a table. I need to populate the drop-down list with a specific field ("percentage") of all lines, and when I click to make the "value" a field of the row identifier.

Is there an easy way to do this? Thanks

+3
source share
1 answer

You will need the following:

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

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

You do not need to worry about assigning a value to a click. Just do it when you load DropDownList first.

+11
source

Source: https://habr.com/ru/post/1770323/


All Articles