Hello, I have a dropdown box that pull data from a sql database. My two important values in the table are Peoples names and a ID key. My dropdown box will list all the peoples names. The issue I am having is how do I know what ID the user picks. My website uses the id to display the correct page, ie. I have www.mydomain.com/name.aspx?ID=1. As some of the values in the table have been deleted they are not in order, so there may be ID=1, but ID=2 is deleted. Thanks.
List items in ASP.NET have both a text and a value property, you can add an item like this: myDropDown.Items.Add(New ListItem("Sue", "1")) myDropDown.Items.Add(New ListItem("Bob", "3")) Then you all you do is get myDropDown.SelectedItem.Value after the user makes a selection.
When do adding records to ur drop down list use the following code dropdown.datasource = yourdatasourcename; dropdown.DataTextField = "name"; dropdown.DataValueField = "id"; dropdown.DataBind(); whenever user click select a name in your dropdown list u can easily identify the id by using int id = dropdown.selectedItem.value;