I have a GridView in ASP.NET, inside a column on this GridView I have the below controls:
<asp:TemplateField>
<ItemTemplate>
<input id='<%#Eval("po_asn_number") %>' class="css-checkbox" type="checkbox" />
<label for='<%#Eval("po_asn_number") %>' name="lbl_1" class="css-label"></label>
<asp:HiddenField ID="poid" runat="server" Value='<%#Eval("po_asn_number") %>' />
</ItemTemplate>
</asp:TemplateField>
This is my OnClick event in the Code Behind.
protected void create_Click(object sender, EventArgs e)
{
foreach (GridViewRow gvr in GridView1.Rows)
{
HiddenField poid = ((HiddenField)gvr.Cells[0].FindControl("poid"));
if (((HtmlInputCheckBox)gvr.FindControl(poid.Value)).Checked == true)
{
Response.Redirect("ShipmentDetail.aspx?id=" + poid.Value);
}
else
{
//Do nothing
}
}
}
What I'm trying to do here first, I look for a HiddenField which the value is the ID for the <input type="checkbox" />
. I am then checking to see if the checkbox
is checked. If it is then do something else do nothing.
When click the button I get an error:
Object reference not set to an instance of an object
Line 48: if (((HtmlInputCheckBox)gvr.FindControl(checkbox)).Checked == true)
Line 49: {
Line 50: Response.Redirect("ShipmentDetail.aspx?id=" + poid.Value);
Any help you can provide will appreciated.