R
rn5a
All the rows in a DataGrid, including the Header, are accompanied with
a CheckBox. I want that when the CheckBox in the Header is checked,
then all the CheckBoxes should automatically get checked. I set the
AutoPostBack property of the CheckBox in the Header to True & am
invoking a sub named 'CheckAllRows' on the CheckedChanged event of this
CheckBox. The CheckBox in the Header exists within the HeaderTemplate
of a TemplateColumn in the DataGrid & the rest of the CheckBoxes reside
within the ItemTemplate of the same TemplateColumn. This is the code
(the ID of the CheckBox in the Header is 'chkHeader' & the IDs of the
rest of the CheckBoxes are 'chkItem'):
Sub CheckAllRows(ByVal obj As Object, ByVal ea As EventArgs)
Dim chkAllRows As CheckBox
Dim chkSelHeader As CheckBox
Dim dgItem As DataGridItem
For Each dgItem In dg1.Items
If (dgItem.ItemType = ListItemType.Header) Then
chkSelHeader = dgItem.FindControl("chkHeader")
Response.Write("hello<br>")
If (chkSelHeader.Checked) Then
If (dgItem.ItemType = ListItemType.Item Or
dgItem.ItemType = ListItemType.AlternatingItem) Then
chkAllRows = dgItem.FindControl("chkItem")
chkAllRows.Checked = True
End If
End If
End If
Next
End Sub
Now when I check the CheckBox in the Header, then the page posts but
none of the CheckBoxes apart from the CheckBox in the Header get
checked. Also notice the Response.Write("hello<br>") line which is
within the first If condition. Even that line doesn't get executed
since after post back, the page doesn't display the text 'hello'.
What am I doing wrong here?
a CheckBox. I want that when the CheckBox in the Header is checked,
then all the CheckBoxes should automatically get checked. I set the
AutoPostBack property of the CheckBox in the Header to True & am
invoking a sub named 'CheckAllRows' on the CheckedChanged event of this
CheckBox. The CheckBox in the Header exists within the HeaderTemplate
of a TemplateColumn in the DataGrid & the rest of the CheckBoxes reside
within the ItemTemplate of the same TemplateColumn. This is the code
(the ID of the CheckBox in the Header is 'chkHeader' & the IDs of the
rest of the CheckBoxes are 'chkItem'):
Sub CheckAllRows(ByVal obj As Object, ByVal ea As EventArgs)
Dim chkAllRows As CheckBox
Dim chkSelHeader As CheckBox
Dim dgItem As DataGridItem
For Each dgItem In dg1.Items
If (dgItem.ItemType = ListItemType.Header) Then
chkSelHeader = dgItem.FindControl("chkHeader")
Response.Write("hello<br>")
If (chkSelHeader.Checked) Then
If (dgItem.ItemType = ListItemType.Item Or
dgItem.ItemType = ListItemType.AlternatingItem) Then
chkAllRows = dgItem.FindControl("chkItem")
chkAllRows.Checked = True
End If
End If
End If
Next
End Sub
Now when I check the CheckBox in the Header, then the page posts but
none of the CheckBoxes apart from the CheckBox in the Header get
checked. Also notice the Response.Write("hello<br>") line which is
within the first If condition. Even that line doesn't get executed
since after post back, the page doesn't display the text 'hello'.
What am I doing wrong here?