In ASP.NET 4, I have a GridView, which contains a DropDownList in the asp:TemplateEdit section. The DropDownList is populating with all of the options I need from a second data source. However, I would like to have each DropDownList in each row have a different SelectedIndex set on default based on data already in the GridView.
For example, here is sample data
| id | Status | hidden | First Name |
--------------------------------------------------
| 12 | <dropdown> | 3 | john doe |
| 13 | <dropdown> | 7 | jane ble |
so you will note the 3rd column is hidden, meaning I have it set to:
<asp:BoundField DataField="StatusName" HeaderText="Status" Visible="false" />
However, the edited row in this column contains the value (asp:BoundField) that I need the DropDownList to display by default.
In other words I need
<option select="selected">something</option>
to have the proper index selected based on the number in the "hidden" field.
You can subscribe to
RowDataBoundevent in order to select the right value in the drop-down list: