Get DataKey value on check box checked event in a GridView
Here is the .aspx code for the following:-
<asp:GridView ID="grdTest" runat="server" AutoGenerateColumns="False" DataKeyNames="ID">
<Columns>
<asp:TemplateField HeaderText="Is Released" >
<ItemTemplate>
<asp:CheckBox ID="chkReleased" runat="server" OnCheckedChanged="chkReleased_CheckedChanged" AutoPostBack="true" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Write the following code on C# page.
protected void chkReleased_CheckedChanged(object sender, EventArgs e)
{
CheckBox chkreleased = (CheckBox)sender;
GridViewRow row = (GridViewRow)chkreleased.NamingContainer;
string Id = grdTest.DataKeys[row.RowIndex].Value.ToString();
}
0 Comment(s)