ImageButton in column's HeaderTemplate doesn't generate Click event

Discussion in 'ASP .Net Datagrid Control' started by Stephen Miller, Feb 15, 2004.

  1. 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
     
    Stephen Miller, Feb 15, 2004
    #1
    1. Advertising

  2. Stephen Miller

    Jos Guest

    Stephen Miller wrote:
    > 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


    You forgot to set the button's OnClick event to be handled by your
    imgCheck_Click handler.
    Just add OnClick="imgCheck_Click" to the ImageButton.

    --

    Jos Branders
     
    Jos, Feb 15, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SiBNY0Q=?=

    Click event on an ImageButton column

    =?Utf-8?B?SiBNY0Q=?=, Feb 23, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    2,443
    Martin Dechev
    Feb 24, 2004
  2. Chu
    Replies:
    2
    Views:
    909
    Winista
    Apr 10, 2006
  3. J McD

    Click event on ImageButton column in a datagrid

    J McD, Feb 23, 2004, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    132
    J McD
    Feb 23, 2004
  4. James Tsao
    Replies:
    0
    Views:
    266
    James Tsao
    Oct 25, 2004
  5. Ryan Taylor
    Replies:
    1
    Views:
    199
    Ryan Taylor
    Jan 13, 2005
Loading...

Share This Page