Results 1 to 5 of 5

Thread: Check All Checkboxes

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    22

    Question Check All Checkboxes

    Hello,

    I have a grid with several checkbox template columns. I am trying to write a method that would check all checkboxes within the grid.

    Any idea?

  2. #2
    Addicted Member Hole-In-One's Avatar
    Join Date
    Mar 2003
    Location
    Minnesota
    Posts
    195
    Without any code code its hard to give you an example but just use a loop.

  3. #3
    Frenzied Member <ABX's Avatar
    Join Date
    Jul 2002
    Location
    Canada eh...
    Posts
    1,622
    Code will check all checkbox controls on a form
    VB Code:
    1. Dim c As Control
    2.  
    3.         For Each c In Me.Controls
    4.             If TypeOf (c) Is CheckBox Then
    5.                 CType(c, CheckBox).Checked = True
    6.             End If
    7.         Next
    Tips:
    • Google is your friend! Search before posting!
    • Name your thread appropriately... "I Need Help" doesn't cut it!
    • Always post your code!!!! We can't read your mind!!! (well, at least most of us!)
    • Allways Include the Name and Line of the Exception (if one is occuring!)
    • If it is relevant state the version of Visual Studio/.Net Framwork you are using (2002/2003/2005)


    If you think I was helpful, rate my post
    IRC Contact: Rizon/xous ChakraNET/xous Freenode/xous

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    22
    Thank you ABX, I had tried this and it is not going down to the grid's controls.

    Below is my trace, it goes from Datagrid to LiteralControl without going through the grid child controls.


    grdWindows:dataGrid1 System.Web.UI.WebControls.DataGrid 29470 356
    grdWindows:dataGrid1:_ctl0 System.Web.UI.WebControls.DataGridTable 29470 0
    grdWindows:dataGrid1:_ctl1 System.Web.UI.WebControls.DataGridItem 586 0
    grdWindows:dataGrid1:_ctl1:_ctl6 System.Web.UI.WebControls.TableCell 129 0
    grdWindows:dataGrid1:_ctl1:_ctl0 System.Web.UI.WebControls.DataGridLinkButton 81 0
    grdWindows:dataGrid1:_ctl1:_ctl7 System.Web.UI.WebControls.TableCell 128 0
    grdWindows:dataGrid1:_ctl1:_ctl1 System.Web.UI.WebControls.DataGridLinkButton 82 0
    grdWindows:dataGrid1:_ctl1:_ctl8 System.Web.UI.WebControls.TableCell 0 0
    grdWindows:dataGrid1:_ctl1:_ctl9 System.Web.UI.WebControls.TableCell 134 0
    grdWindows:dataGrid1:_ctl1:_ctl2 System.Web.UI.WebControls.dataGridLinkButton 88 0
    grdWindows:dataGrid1:_ctl1:_ctl10 System.Web.UI.WebControls.TableCell 132 0
    grdWindows:dataGrid1:_ctl1:_ctl3 System.Web.UI.WebControls.DataGridLinkButton 86 0
    grdWindows:dataGrid1:_ctl1:_ctl11 System.Web.UI.WebControls.TableCell 0 0
    grdWindows:dataGrid1:_ctl1:_ctl4 System.Web.UI.WebControls.DataGridLinkButton 0 0
    grdWindows:dataGrid1:_ctl1:_ctl12 System.Web.UI.WebControls.TableCell 0 0
    grdWindows:dataGrid1:_ctl1:_ctl5 System.Web.UI.WebControls.DataGridLinkButton 0 0
    grdWindows:dataGrid1:_ctl2 System.Web.UI.WebControls.DataGridItem 326 0
    grdWindows:dataGrid1:_ctl2:_ctl2 System.Web.UI.WebControls.TableCell 132 0
    grdWindows:dataGrid1:_ctl2:_ctl0 System.Web.UI.WebControls.CheckBox 121 0
    grdWindows:dataGrid1:_ctl2:_ctl3 System.Web.UI.WebControls.TableCell 112 0
    grdWindows:dataGrid1:_ctl2:_ctl1 System.Web.UI.WebControls.CheckBox 103 0
    grdWindows:dataGrid1:_ctl2:_ctl4 System.Web.UI.WebControls.TableCell 0 28
    grdWindows:dataGrid1:_ctl2:_ctl5 System.Web.UI.WebControls.TableCell 24 48
    grdWindows:dataGrid1:_ctl2:_ctl6 System.Web.UI.WebControls.TableCell 28 52
    grdWindows:dataGrid1:_ctl2:_ctl7 System.Web.UI.WebControls.TableCell 0 28
    grdWindows:dataGrid1:_ctl2:_ctl8 System.Web.UI.WebControls.TableCell 0 28
    ........
    grdWindows:_ctl0 System.Web.UI.LiteralControl 2 0
    grdWindows:txtkey System.Web.UI.WebControls.TextBox 0 40
    grdWindows:_ctl1 System.Web.UI.LiteralControl 2 0
    grdWindows:txtKeyColumn System.Web.UI.WebControls.TextBox 0 28
    grdWindows:_ctl2 System.Web.UI.LiteralControl 2 0
    grdWindows:txtCurrentPage System.Web.UI.WebControls.TextBox 0 28
    grdWindows:_ctl3 System.Web.UI.LiteralControl

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2004
    Posts
    22

    Thumbs up

    I was trying to avoid loops within loop, but I got it to work.

    Dim item As DataGridItem
    Dim i As Integer
    Dim j As Integer

    For Each item In DataGrid1.Items
    For i = 0 To item.Cells.Count - 1
    For j = 0 To item.Cells(i).Controls.Count - 1
    If TypeOf item.Cells(i).Controls(j) Is CheckBox Then
    CType(item.Cells(i).Controls(j), checkBox).Checked = True
    End If
    Next
    Next
    Next


    If anyone has a suggestion on how to avoid multiple loops, please let know.

    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width