I want to display a dropdownlist inside one cell in my gridview when the user clicks edit. The user should then be able to select an option from the dropdownlist then click update and the selected option will be stored in the cell as text. The gridview is populated using a dataset which is created according to information selected by the user.
During the row editing event I remove the textbox control from the cell then add the dropdownlist which is populated from a database table. This displays fine but the dropdown list then can't be found inside the row updating event.
Here is a my code:
Sub GridView_RowEditing event
GridView.EditIndex = e.NewEditIndex
Dim ddl As New DropDownList
ddl.ID = "DropDownList1"
'Populate dropdownlist from database
Sub GridView_RowUpdating event
Dim row As GridViewRow
Dim row2 As DataRow
row = CType(GridView.Rows(e.RowIndex), GridViewRow)
'I construct the new row (row2) here and try to find the dropdownlist to get something out of it but throws a null refference exception.
row2(6) = CType(row.Cells(7).FindControl("DropDownList1"), DropDownList).Items(0).Text
View Complete Post