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

C

Charles

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
 
L

Luke Zhang [MSFT]

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.)
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top