Capture CheckBox Click Event

Discussion in 'ASP .Net Datagrid Control' started by news.microsoft.com, Dec 13, 2003.

  1. I have a datagrid with a checkbox column. The column is bound to adatabase,
    and I have no problem capturing a click event on the checkbox using the
    OnCheckChanged event handler.

    Here is a sample of the html used to build the column:
    <asp:TemplateColumn HeaderText="Crew Chief?">
    <HeaderStyle HorizontalAlign="Center" Width="40px"
    VerticalAlign="Middle"></HeaderStyle>
    <ItemStyle HorizontalAlign="Center"></ItemStyle>
    <ItemTemplate>
    <asp:checkbox id=chkChief runat="server"
    cssclass="FormFieldText2"
    OnCheckedChanged="cbChief_Clicked"
    COMMANDARGUMENT='<%#Container.DataItem("SAN") %>'
    AutoPostBack=True Checked='<%#
    bSetCheckValue(Container.DataItem("IsChief"))%>'>
    </asp:checkbox>
    </ItemTemplate>
    </asp:TemplateColumn>

    The event handler function fires and I get a reference to the checkbox
    object that was clicked.

    The problem is that I am trying to get a reference to the row that the
    checkbox was clicked in to retrieve the datakey value. I know I could loop
    through the entire dataitem list and find the match, but what I was trying
    to do was pass the datakey value for the row as a command arguement, so that
    I can use the datakey value directly in the event handler.

    Has anyone been able to make this work?

    Thanks,
    Marc.
    news.microsoft.com, Dec 13, 2003
    #1
    1. Advertising

  2. news.microsoft.com

    Marc Rivait Guest

    Here is the answer to my post. Thanks to Michael.

    protected void cbChief_Clicked(object sender, EventArgs e) {

    string _val = ((CheckBox)sender).Attributes["COMMANDARGUMENT"]; // Here we
    received value in the attribute of checkbox.

    foreach(DatagridItem dr in Datagring.Items)

    {

    // your code.

    }

    }



    The Best Regards,

    Net Developer

    Michael Tkachev



    "news.microsoft.com" <> wrote in message
    news:...
    > I have a datagrid with a checkbox column. The column is bound to

    adatabase,
    > and I have no problem capturing a click event on the checkbox using the
    > OnCheckChanged event handler.
    >
    > Here is a sample of the html used to build the column:
    > <asp:TemplateColumn HeaderText="Crew Chief?">
    > <HeaderStyle HorizontalAlign="Center" Width="40px"
    > VerticalAlign="Middle"></HeaderStyle>
    > <ItemStyle HorizontalAlign="Center"></ItemStyle>
    > <ItemTemplate>
    > <asp:checkbox id=chkChief runat="server"
    > cssclass="FormFieldText2"
    > OnCheckedChanged="cbChief_Clicked"
    > COMMANDARGUMENT='<%#Container.DataItem("SAN") %>'
    > AutoPostBack=True Checked='<%#
    > bSetCheckValue(Container.DataItem("IsChief"))%>'>
    > </asp:checkbox>
    > </ItemTemplate>
    > </asp:TemplateColumn>
    >
    > The event handler function fires and I get a reference to the checkbox
    > object that was clicked.
    >
    > The problem is that I am trying to get a reference to the row that the
    > checkbox was clicked in to retrieve the datakey value. I know I could

    loop
    > through the entire dataitem list and find the match, but what I was trying
    > to do was pass the datakey value for the row as a command arguement, so

    that
    > I can use the datakey value directly in the event handler.
    >
    > Has anyone been able to make this work?
    >
    > Thanks,
    > Marc.
    >
    >
    Marc Rivait, Dec 16, 2003
    #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. Purvi T
    Replies:
    0
    Views:
    802
    Purvi T
    Oct 19, 2004
  2. Viny
    Replies:
    1
    Views:
    4,027
    Mike Moore [MSFT]
    Oct 24, 2003
  3. Chu
    Replies:
    2
    Views:
    889
    Winista
    Apr 10, 2006
  4. Max2006
    Replies:
    2
    Views:
    1,546
    Walter Wang [MSFT]
    Sep 19, 2007
  5. dave

    stumped...table - row - click event, cancel checkbox event

    dave, Sep 2, 2006, in forum: ASP .Net Building Controls
    Replies:
    0
    Views:
    211
Loading...

Share This Page