gridview checkbox how to fire an event when it is checked
Iam having a grid which consists of check box. When user checks on any of the checkbox of the grid .I want to fire
example of my code is like this
rowcommand
event so that some database operation has to done based on the checkbox .rowcommand
event is firing for only for button, but how can I do the same for the checkboxexample of my code is like this
<asp:GridView ID="GridView1" runat="server" onrowcommand="GridView1_RowCommand">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Use
<asp:checkbox id="CheckBox1" runat="server" oncheckedchanged="CheckBox1_CheckedChanged" xmlns:asp="#unknown" />
and then tryprotected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox chk = (CheckBox)sender;
GridViewRow gr = (GridViewRow)chk.Parent.Parent;
lblmsg.Text = GridView1.DataKeys[gr.RowIndex].Value.ToString();
//lblmsg.Text = "Hello";
}
Try this,
Modify Checkbox in Gridview like,
<asp:TemplateField HeaderText="View">
<ItemTemplate>
<asp:CheckBox ID="chkview" runat="server" AutoPostBack="true" OnCheckedChanged="chkview_CheckedChanged" />
</ItemTemplate>
</asp:TemplateField>
And on Code view define, protected void chkview_CheckedChanged(object sender, EventArgs e)
{
//Define your code here.
}