vendredi 5 février 2016

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?

HTML

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

C#

protected void btnC_Click(object sender, EventArgs e)
{
try
{
    foreach (GridViewRow row in dgRD.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; }
}




Aucun commentaire:

Enregistrer un commentaire