We need to do when checkbox clicked then some action affected to that row, for example getting datakey, rowindex or getting cell value.
ASPX
<asp:TemplateField> <ItemTemplate> <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="True" oncheckedchanged="CheckBox1_CheckedChanged" /> </ItemTemplate> </asp:TemplateField>
This sample code is getting gridviewrow from checkbox checked changed event then displaying value from another cell to a label.
C#
protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { GridViewRow gvrow = ((Control)sender).Parent.Parent as GridViewRow; Label1.Text = gvrow.Cells[2].Text; }
Using Naming Container
protected void CheckBox1_CheckedChanged(object sender, EventArgs e) { GridViewRow row=(GridViewRow)(((CheckBox)sender).NamingContainer); }
No comments:
Post a Comment