Capture CheckBox Click Event

Ask a Question related to ASP.NET Data Grid Control, Design and Development.

  1. #1

    Default Capture CheckBox Click Event

    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 Guest

  2. Similar Questions and Discussions

    1. double click causes click-event anddoubleClick-event
      I too am interested in a response to this. I see all kinds of information on how to enable the double-click event, but not how to distinguish...
    2. stumped...table - row - click event, cancel checkbox event
      I have a html table and mutliple rows. On each row i put an onclick event that opesn a modal window and prompts the user for some information. I...
    3. how to use click event on a checkbox in cfgrid
      I am using checkboxes in a cfgrid by putting type="boolean" in my cfgridcolumn tag The problem is, I need a click event to be fired when any of the...
    4. Button.Init? how Do I know if click event has been fired? TextBox.TextChanged event before Button.Click in a CompositeCustomControl.
      Hello I have the following situation: (everything is dynamic (controls.add)) 1. Button.Init { WasButtonClickFired = true } 2....
    5. How Do I : Add a Click event to a checkbox in a DataGrid
      Hello, I need to know when a user clicks a checkbox, in a datagrid, so I can then update the database. I.E. I need to know which row has been...
  3. #2

    Default Re: Capture CheckBox Click Event

    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" <nospam@rivaitsoftware.com> wrote in message
    news:OiFXtAYwDHA.1908@TK2MSFTNGP10.phx.gbl...
    > 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 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139