Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Nested gridview select All

Posted on 2009-07-06
3
Medium Priority
?
761 Views
Last Modified: 2012-06-27
I have a gridview within a gridview.

I want to be able once selecting the inner gridview to select all the items via a checkbox in the header template.

I was using http://www.aspboy.com/Categories/GridArticles/Hierarchical_GridView_With_Clickable_Rows.aspx asa a basis for my code.

Iv'e tried the following code to see if i could figure it out but it does not recognise my cbAll (the checkbox in the headertemplate of the child gridview)
Protected Sub cbAll_CheckChanged(ByVal s As Object, ByVal e As EventArgs)
        Dim blnChecked As Boolean = False
 
 
        For Each gvRow As GridViewRow In gvParent.Rows
            '// get the checkboxed items for the assets
            Dim gvChildAsset As GridView = (DirectCast(gvRow.FindControl("gvChildAssets"), GridView))
            '// for each of the rows in the child task gridview
            ' For Each dc System.web.DataControlField in gvchildasset.columns
            For Each dc As DataControlField In gvChildAsset.Columns
                If TypeOf dc Is TemplateField Then
                    Dim cbAll As CheckBox = (DirectCast(gvChildAsset.FindControl("cbAll"), CheckBox))
                    If isNull(cbAll) Then Continue For
                    If cbAll.Checked Then
                        blnChecked = True
                        Exit For
                    End If
                End If
            Next
 
            For Each gvChildAssetRow As GridViewRow In gvChildAsset.Rows
                Dim cb As CheckBox = (DirectCast(gvChildAssetRow.FindControl("cb"), CheckBox))
                If isNull(cb) Then Continue For
                If blnChecked Then
                    cb.Checked = True
                End If
            Next
        Next
    End Sub

Open in new window

0
Comment
Question by:ddl_ex5
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 24794043
It looks like you are calling FindControl from the GridView, but you need to call it from the GridViewRow.

GridViewRow line:

     Dim gvChildAsset As GridView = (DirectCast(gvRow.FindControl("gvChildAssets"), GridView))
 
GridView line:

     Dim cbAll As CheckBox = (DirectCast(gvChildAsset.FindControl("cbAll"), CheckBox))

The second line needs to be more like the first line.
 
0
 

Author Comment

by:ddl_ex5
ID: 24803342
Putting
Dim cbAll As CheckBox = (DirectCast(gvChildAsset.FindControl("cbAll"), CheckBox)) into a for each loop for the childAsset row does not work.  This was my first attempt before i got the checkbox of cbAll to be located.

0
 
LVL 96

Accepted Solution

by:
Bob Learned earned 1500 total points
ID: 24803445
I guess that I didn't make myself clear enough.  You need to use FindControl with a row from gvChildAsset, not the GridView itself.

Example:
    Dim cbAll As CheckBox = TryCast(gvChildAsset.Rows(0).FindControl("cbAll"), CheckBox)
0

Featured Post

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question