S
Stephen Miller
I have a datagrid, with a template column containing a CheckBox called
chkSelect in the ItemTemplate. Users select rows to edit/delete by
checking the appropriate checkbox.
I want to add a simple image button to the HeaderTemplate that enables
users to auto select all rows (ie Hotmail):
<asp:TemplateColumn headertext="">
<HeaderTemplate>
<asp:ImageButton id="imgCheck" runat="server"
ImageUrl="check.gif"></asp:ImageButton>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox id="chkSelect" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
The code behind for the ImageButton's Click event is simply:
Private Sub imgCheck_Click(ByVal sender As System.Object, _
ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgCheck.Click
Dim myItem As DataGridItem
Dim myChkBox As CheckBox
For Each myItem In myDataGrid.Items
myChkBox = CType(myItem.Cells(0).FindControl("chkSelect"), CheckBox)
myChkBox.Checked = True
Next
End Sub
The problem is that the ImageButton's Click event is not being called
when nested in the column's HeaderTemplate. If I move the ImageButton
and place it elsewhere on the page, the code work's fine.
What am I doing wrong?
Thanks,
Stephen
chkSelect in the ItemTemplate. Users select rows to edit/delete by
checking the appropriate checkbox.
I want to add a simple image button to the HeaderTemplate that enables
users to auto select all rows (ie Hotmail):
<asp:TemplateColumn headertext="">
<HeaderTemplate>
<asp:ImageButton id="imgCheck" runat="server"
ImageUrl="check.gif"></asp:ImageButton>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox id="chkSelect" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
The code behind for the ImageButton's Click event is simply:
Private Sub imgCheck_Click(ByVal sender As System.Object, _
ByVal e As System.Web.UI.ImageClickEventArgs) Handles imgCheck.Click
Dim myItem As DataGridItem
Dim myChkBox As CheckBox
For Each myItem In myDataGrid.Items
myChkBox = CType(myItem.Cells(0).FindControl("chkSelect"), CheckBox)
myChkBox.Checked = True
Next
End Sub
The problem is that the ImageButton's Click event is not being called
when nested in the column's HeaderTemplate. If I move the ImageButton
and place it elsewhere on the page, the code work's fine.
What am I doing wrong?
Thanks,
Stephen