|
-
Mar 19th, 2004, 04:58 PM
#1
Thread Starter
Junior Member
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?
-
Mar 19th, 2004, 05:27 PM
#2
Addicted Member
Without any code code its hard to give you an example but just use a loop.
-
Mar 20th, 2004, 02:13 AM
#3
Code will check all checkbox controls on a form
VB Code:
Dim c As Control
For Each c In Me.Controls
If TypeOf (c) Is CheckBox Then
CType(c, CheckBox).Checked = True
End If
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
-
Mar 22nd, 2004, 09:53 AM
#4
Thread Starter
Junior Member
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
-
Mar 22nd, 2004, 12:22 PM
#5
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|