Problem "seeing" unbound checkboxes in nested gridview

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • GISmatters
    New Member
    • Mar 2008
    • 3

    Problem "seeing" unbound checkboxes in nested gridview

    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 cmdEmailSelecte dFiles_Click(By Val sender As Object, ByVal e As System.EventArg s) Handles cmdEmailSelecte dFiles.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.R ows.Count - 1 ' this works - it iterates the correct number of times
    If (gvDocsAndRpts. Rows(r1).RowTyp e = DataControlRowT ype.DataRow) Then
    nestedGV = CType(gvDocsAnd Rpts.Rows(r1).F indControl("gvD ocFileSelect"), GridView)
    For r2 = 0 To nestedGV.Rows.C ount - 1 ' this doesn't work - nestedGV.Rows.C ount is always zero
    If CType(nestedGV. Rows(r2).FindCo ntrol("chkToEma il"), CheckBox).Check ed 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
  • GISmatters
    New Member
    • Mar 2008
    • 3

    #2
    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...

    Comment

    • GISmatters
      New Member
      • Mar 2008
      • 3

      #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.

      Comment

      Working...