Showing posts from July, 2008

DataBinding DropDown SelectedValue Property

While working on an application I found the need to databind the SelectedValue property of a drop down. However I noticed that intellisense doesn't pick it up. So I asked around and was told that even though it doesn't show up using intellisense it does work. So I tried it and sure enough it worked wonderfully.

Now the value of this may not be apparent but if you are doing custom in line editing in a grid for example it can be very handy you can bind the default value of the drop down to what the value for that field is currently and populate the drop down with a list of all valid values. Additionally you can just call Databind on the grid in that case and it will populate the elements for you if you have it setup correctly.

To see what I'm talking about look at this example.

<asp:GridView runat="server" ID="gvSample" DataSource='<%# GetFavoriteFoodList() %>'>
<asp:BoundField DataField="U…