By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,968 Members | 1,852 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,968 IT Pros & Developers. It's quick & easy.

Problem "seeing" unbound checkboxes in nested gridview

P: 3
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
Mar 6 '08 #1
Share this Question
Share on Google+
2 Replies


P: 3
Quick amendment: I lightly edited the code I posted to focus it, but in the process I renamed the loop variables and forgot to rename them at the bottoms of the loops... rest assured the real code doesn't have that error, and that is not the explanation for my problems...
Mar 6 '08 #2

P: 3
Problem resolved.

The problem was due to viewstate being disabled on the parent gridview. I had disabled viewstate long ago and was adding the nested gridview as a new feature - it didn't occur to me to even think about viewstate, in part because I could see some of the information about the nested gridview... of course, in hindsight I realize that the information I could see is all the static properties specified in the .aspx file.
Mar 7 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.