Loop through rows to get control value within nested gridview ASP.NET 2.0
Posted on 2007-11-30
Scenario: Gridview with employee, nested gridview with tasks that require completion, an item template within nested gridview that has a dropdown box where the user selects whether the task is completed, in process, not started, etc. An update button in the employee item tempate field (in same cell as nested gridview) that houses the nested gridview. When the update button is clicked, I want to iterate through the nested gridview and get the new value of the dropdownlist and send it to the database.
Protected Sub btnUpdate_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim gvInside As GridView = CType(FindControl("gvTasks"), GridView)
Dim iStatus As Integer
Dim StatusBox As DropDownList
For Each row As GridViewRow In gvInside.Rows
StatusBox = CType(FindControl("ddCompletionStatus"), DropDownList)
iStatus = StatusBox.SelectedValue
The code above generates the following error: System.NullReferenceException was unhandled by user code Message="Object reference not set to an instance of an object."
Any help is appreciated. Thank you!