Capture Checked Value From Data Grid

I continue to get an error of

Object not set to instance of object

What do I need to change so that this code can execute succesfully?


<td valign="top" style="text-align: left; width: 200px;">
<asp:GridView runat="server" ID="datagridTest" AutoGenerateColumns="false" GridLines="Both" ShowFooter="true" >
<asp:BoundField DataField="field1" HeaderText="1st Set" />
<asp:BoundField DataField="field2" HeaderText="2nd Set" />
        <asp:Label runat="server" Text='<%#Eval("categoryID") %>' ID="managerID" Visible="false"></asp:Label>
        <asp:CheckBox ID="Checked" runat="server" AutoPostBack="false" Checked='<%# Convert.ToBoolean(Eval("Checked")) %>' />
<asp:Button runat="server" ID="btnChecked" CssClass="Buttons" Text="Add" OnClick="btnC_Click" />


protected void btnC_Click(object sender, EventArgs e)
    foreach (GridViewRow row in datagridTest.Rows)
        string ID = ((Label)row.FindControl("managerID")).Text;
        if (row.RowType == DataControlRowType.DataRow)
            CheckBox chk = (CheckBox)row.FindControl("Checked");
            if (chk.Checked) {}
            else {}
catch (Exception exception) { throw exception; }


in your html you are setting your gridviews id as


but in the code behind you use "dgRD".this may be the root your problem.

Need Your Help

Overlaying several CLR reference fields with each other in explicit struct?

c# .net struct clr

Edit: I'm well aware of that this works very well with value types, my specific question is about using this for reference types.

How does implementing multiple COM interfaces work in C++?

c++ com static-cast multiple-interface-implem

I am trying to understand this example code regarding Browser Helper Objects.