How Do I : Add a Click event to a checkbox in a DataGrid

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

  1. #1

    Default 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 clicked and which column.
    Charles

    Charles Guest

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. Checkbox in Datagrid doesn't fire event
      I've added a Checkbox control to a Datagrid and would like to Enable/Disable a button based on whether the checkbox is checked. However, I'm trying...
    4. Click anywhere in a datagrid row to change checkbox column state
      Yes. In ItemDataBound event filter out non-data items (header, footer) and for data items loop through Cells collection to set...
    5. 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...
  3. #2

    Default Re: How Do I : Add a Click event to a checkbox in a DataGrid

    Check out
    [url]http://www.c-sharpcorner.com/Code/2003/June/DataGridAndCheckBoxes.asp[/url]

    Regards
    Sushila
    ..NET MVP

    "Charles" <CWildner@Bellsouth.net> wrote in message news:068d01c347c5$bb3c81a0$a001280a@phx.gbl...
    > 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 clicked and which column.
    > Charles
    >
    Sonali.NET[MVP] Guest

  4. #3

    Default Re: How Do I : Add a Click event to a checkbox in a DataGrid

    Miss Sushila,

    Can this be "compressed" some more step? I was hoping for a one click
    solution. And your example is a two click solution.


    Thank you for responding.
    Charles


    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!

    Charles Wildner Guest

  5. #4

    Default RE: How Do I : Add a Click event to a checkbox in a DataGrid

    You may need to set the CheckBox's AutoPostBack to true, see following
    sample


    <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 45px; POSITION:
    absolute; TOP: 28px" runat="server" Height="194px" Width="369px"
    DataSource="<%# DataSet11 %>" DataMember="Table1"
    AutoGenerateColumns="False">

    <HeaderStyle BackColor="#aaaadd">
    </HeaderStyle>

    <Columns>


    <asp:TemplateColumn >

    <ItemTemplate >
    <asp:CheckBox id="CheckBox1" AutoPostBack="True" Runat ="server"
    OnCheckedChanged ="CheckBox1_CheckedChanged">
    </asp:CheckBox>
    ...

    </ItemTemplate>

    </asp:TemplateColumn>

    </Columns>


    </asp:DataGrid>


    Public Sub CheckBox1_CheckedChanged(ByVal sender As System.Object,
    ByVal e As System.EventArgs)

    Dim cbox As CheckBox
    cbox = sender
    Response.Write(cbox.ClientID)

    End Sub

    The clientID should be like:

    DataGrid1__ctl4_CheckBox1

    And you get the row and column inforamtion form the string, for example,
    current row is 4 (from "ctl4")

    Luke

    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Luke Zhang [MSFT] 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