I have unbound checkboxes in a nested gridview to allow multi-selection of "child" rows. For context, the parent gridview rows are for large "reports", the child rows are for various specific files comprising each report. I want the user to be able to select an arbitrary collection of report files and have them emailed by clicking an "Email selected files" button.
Everything displays properly, including the checkboxes for each child row (each file), but on postback (after clicking the "Email selected files" button), I cannot "see" any child rows when iterating through the rows of the parent gridview. What's odd is that I can see the nested (child) gridview as a GridView object that has the correct number of columns, the correct column headings, the correct DataSourceID, etc..., but this nested gridview's rowcount is always zero.
I have read lots of posts on how to create nested gridviews, and that doesn't seem to be the problem. I am setting the nested gridview's datasource in the parent gridview's RowDataBound event. I can successfully manipulate the nested gridview (e.g., making some columns invisible) in the parent's PreRender event. And as I said, the display renders perfectly. The problem is that on post-back, I can't seem to actually find and act on the selected (checked) checkboxes...
Elsewhere, I have successfully implemented unbound checkboxes in a gridview and processed them in a button click event handler when no nesting is involved, so my current effort has been to adapt that approach for the nested gridview. Here's the button click handler that I have created and expect to be "seeing" the checkboxes, but it's not:
Protected Sub cmdEmailSelectedFiles_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmdEmailSelectedFiles.Click
' NOTE: parent gridview is named gvDocsAndRpts; child gridview is named gvDocFileSelect
Dim r1 As Integer
Dim r2 As Integer
Dim nestedGV As GridView
For r1 = 0 To gvDocsAndRpts.Rows.Count - 1 ' this works - it iterates the correct number of times
If (gvDocsAndRpts.Rows(r1).RowType = DataControlRowType.DataRow) Then
nestedGV = CType(gvDocsAndRpts.Rows(r1).FindControl("gvDocFil eSelect"), GridView)
For r2 = 0 To nestedGV.Rows.Count - 1 ' this doesn't work - nestedGV.Rows.Count is always zero
If CType(nestedGV.Rows(r2).FindControl("chkToEmail"), CheckBox).Checked Then
' code to handle a checked child row
End If
Next n
End If
Next r
' additional processing...
End Sub
Any help very much appreciated. Cheers,
Chris