Putting DB value into a dropdown listbox in a DataGrid
-
I am working with a DataGrid and a Database. What follows is an example of the grid that I want to build (this example works - my question will come after it). I have stripped out most of the properties because they are not relavent to my question. There is an example of building a DataGrid that looks like this... Enabled="false" /> The last column of this grid is a Checkbox. And it is checked or unchecked based on what is in the database. My question is, how can I do something similar with a dropdown listbox? I have a location ID that I want to use to select the correct item in the listbox. But I do not know what property to set to get it to select that item. Here is what I have (but it only selects the first item no matter what the value is in the database)... Arizona Atlanta Cinncinati Washington DC Any help would be greatly appreciated. Johno
-
I am working with a DataGrid and a Database. What follows is an example of the grid that I want to build (this example works - my question will come after it). I have stripped out most of the properties because they are not relavent to my question. There is an example of building a DataGrid that looks like this... Enabled="false" /> The last column of this grid is a Checkbox. And it is checked or unchecked based on what is in the database. My question is, how can I do something similar with a dropdown listbox? I have a location ID that I want to use to select the correct item in the listbox. But I do not know what property to set to get it to select that item. Here is what I have (but it only selects the first item no matter what the value is in the database)... Arizona Atlanta Cinncinati Washington DC Any help would be greatly appreciated. Johno
AFAIK you have to do that in code, by doing something like this:
MyDropDownList.Items.FindByValue(MyValue).Selected = True
If that doesn't work, you may have to just loop through the items and set the drop-down'sSelectedIndex
property manually. Here's a useful link: http://aspnet.4guysfromrolla.com/articles/080702-1.3.aspx[^]