Last post Jan 27, 2014 06:14 PM by salwa.khan
Nov 21, 2007 08:40 PM|BrigideW|LINK
Thanks for your help
Nov 21, 2007 08:52 PM|onSlaught|LINK
Your if statement will always be false.
If (chbx is null) AND (chbx is checked) will always be false since they can't be both. Try removing the first condition (checking for null) or place an OR operator instead of AND. Hope that helps.
Nov 21, 2007 11:01 PM|limno|LINK
Button1 is outside of the GridView:
protected void Button1_Click(object sender, EventArgs e)
CheckBox chbx = GridView1.HeaderRow.FindControl("CheckBox1") as CheckBox;
if (chbx != null && chbx.Checked)
Response.Write("Checkbox 1 is checked ");
Response.Write("Checkbox 1 is not checked!");
Nov 22, 2007 11:14 PM|BrigideW|LINK
It is a dynamic checkBox so on page load it has not created it yet
if I dont check if it is not null I will a error message beside if it is not null then therefore the value of the checkbox could be check or not checked
so the condition is correct
Jan 27, 2014 05:33 PM|salwa.khan|LINK
I've come across with the same problem. I've a GV and inside an ItemTemplate I've a checkbox.
<asp:GridView ID="GridView1" runat="server" AutoGenerateSelectButton="True">
<asp:CheckBox ID="chkApproved" runat="server" CommandName="Approve" AutoPostBack="false" />
Now on btnClick I want to check if the chkbox is checked or not.
protected void btnSubmit_Click(object sender, EventArgs e)
foreach (GridViewRow row in GridView1.Rows)
CheckBox chk = (CheckBox)row.FindControl("chkApproved");
if (chk != null && chk.Checked)
Response.Write("Checkbox is checked");
But this doesn't seem to do anything even if the checkbox is checked or its null.
When debugging it never steps into the If statement when I have the checkbox checked in the browser. Ideas?!
Jan 27, 2014 06:14 PM|salwa.khan|LINK
Hah! FInally overcomed with this issue with just a if(!IsPostback) under the Page_Load!