views:

30

answers:

1

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

+6  A: 

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.

Abe Miessler
You can also do the same in the codebehind if you so wish
skyfoot
Cheers buddy, that works great
Chris