Hello there,
I need check whether CheckBox in GridView is checked or not in c# and ASP.Net
I using this tutorial Implement CheckChanged event of CheckBox inside GridView in ASP.Net
I don't have error but check whether CheckBox in GridView is checked not working.
My code below, please help me, thank you
<asp:TemplateField ItemStyle-HorizontalAlign="Center">
<HeaderTemplate>
<asp:CheckBox ID="chkBxHeader"
AutoPostBack="true" OnCheckedChanged="chkBxHeader_CheckedChanged" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<div>
<asp:CheckBox ID="chkRow" runat="server" />
</div>
</ItemTemplate>
</asp:TemplateField>
protected void chkBxHeader_CheckedChanged(object sender, EventArgs e)
{
try
{
foreach (GridViewRow row in GridView1.Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
CheckBox chkRow = (row.Cells[0].FindControl("chkRow") as CheckBox);
if (chkRow.Checked)
{
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "Alert", "alert('KO');", true);
}
}
}
}
catch (Exception ex)
{
Console.WriteLine("Skipped exception! " + ex);
}
}