Hello,
I get the error message "Object reference not set to an instance of an object." when I try to enable a checkbox in the gridview. Here's my code:
protected void gv_RowEditing(object sender, GridViewEditEventArgs e)
{
int index = Convert.ToInt32(e.NewEditIndex);
Label result = (Label)gv.Rows[index].FindControl("lblResultAuto");
gv.EditIndex = e.NewEditIndex;
if (result.Text == "N/A")
{
CheckBox cbYes = (CheckBox)gvChecks.Rows[index].FindControl("cbResultManualYes");
cbYes.Enabled = true;
CheckBox cbNo = (CheckBox)gvChecks.Rows[index].FindControl("cbResultManualno");
cbNo.Enabled = true;
}
bindChecks();
}
Any kind of help will be appreciated.
Thank you in advance.
<asp:GridView ID="gv" runat="server" AutoGenerateColumns="false"
OnRowCancelingEdit="gv_RowCancelingEdit"
OnRowEditing="gv_RowEditing"
OnRowUpdating="gv_RowUpdating" CssClass="mTable">
<Columns>
<asp:TemplateField HeaderText="Check" ItemStyle-Width="25">
<ItemTemplate>
<asp:Label ID="lblResultAuto" runat="server" Text='<%#Eval("CheckRes") %>' Width="25"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Valid" ItemStyle-Width="25">
<ItemTemplate>
<asp:CheckBox ID="lblResultManual" runat="server" Enabled="False" />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="cbResultManualYes" runat="server" Enabled="false"/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Not Valid" ItemStyle-Width="25">
<ItemTemplate>
<asp:CheckBox ID="lblResultManual1" runat="server" Enabled="False" />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="cbResultManualΝο" runat="server" Enabled="false"/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField >
<ItemTemplate>
<asp:LinkButton ID="btnEdit" Text="Edit" runat="server" CommandName="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnUpdate" Text="Update" runat="server" CommandName="Update" />
<asp:LinkButton ID="btnCancel" Text="Cancel" runat="server" CommandName="Cancel" />
</EditItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>