gridview checkbox how to fire an event when it is checked - DOTNET

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 rowcommand event so that some database operation has to done based on the checkbox .rowcommandevent is firing for only for button, but how can I do the same for the checkbox
 
example 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 try
protected 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.
}
Copyright © 2015 DOTNET All Right Reserved