Hello,
I'm trying to update a record in db from a datagrid. My problem is that the checkboxes are not getting updated. Here's my code:
<asp:GridView ID="gvChecks" runat="server" AutoGenerateColumns="false"
OnRowCancelingEdit="gvChecks_RowCancelingEdit"
OnRowEditing="gvChecks_RowEditing"
OnRowUpdating="gvChecks_RowUpdating" CssClass="mGrid" OnRowDataBound="gvChecks_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="UploadDocID" ItemStyle-Width="25" Visible="false" >
<ItemTemplate>
<asp:Label ID="lblUploadDocID" runat="server" Text='<%#Eval("UploadDocID") %>' Width="25"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Description">
<ItemTemplate>
<asp:Label ID="lblFileDescr" runat="server" Text='<%#Eval("FileDescr") %>' Width="500"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="CheckResult" Visible="false">
<ItemTemplate>
<asp:Label ID="lblCheckResult" runat="server" Text='<%#Eval("DocValid") %>' Width="50"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Yes" >
<ItemTemplate>
<asp:CheckBox ID="cbYes" runat="server" Enabled="false"/>
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="cbYes" runat="server"/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="No" ItemStyle-Width="60">
<ItemTemplate>
<asp:CheckBox ID="cbNo" runat="server" Enabled="false" />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="cbNo" runat="server"/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField ItemStyle-Width="150" >
<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>
protected void gvChecks_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
Label checkID = (Label)gvChecks.Rows[e.RowIndex].FindControl("lblUploadDocID");
CheckBox resYes = (CheckBox)gvChecks.Rows[e.RowIndex].FindControl("cbYes");
CheckBox resNo = (CheckBox)gvChecks.Rows[e.RowIndex].FindControl("cbNo");
string status = String.Empty;
if (resYes.Checked && resNo.Checked)
appObj.myMessageBox("You can only choose one checkbox.");
else
{
if (resYes.Checked)
status = "TRUE";
else
if (resNo.Checked)
status = "FALSE";
else
status = String.Empty;
}
updateApplicationCheckList(checkID.Text, status);
gvChecks.EditIndex = -1;
bindApplicationChecks();
}
catch (Exception ex)
{
myMessageBox(ex.Message);
}
}
status is always empty.
I would appreciate any kind of help.
Thank you.