I have the following asp.net checkbox inside a GridView which is inside an UpdatePanel:
<asp:UpdatePanel ID="upSubasks" ClientIDMode="Static" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<div id="dvSubtasksHolder" runat="server" style="width: 98%;" class="brClear padTop">
<asp:GridView ShowHeaderWhenEmpty="false" ID="gvSubTasks" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="Subtask ID" HeaderText="Subtask ID" HeaderStyle-CssClass="hideTag" ItemStyle-CssClass="hideTag" />
<asp:TemplateField HeaderText="Complete">
<ItemTemplate>
<asp:CheckBox ID="cbIsComplete" runat="server" AutoPostBack="true" Enabled='<%# Eval("Complete Subtask").ToString() == "1" ? false : true %>' Checked='<%# Eval("Complete Subtask").ToString() == "1" ? true : false %>' OnCheckedChanged="cbIsComplete_CheckChanged" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
</ContentTemplate>
</asp:UpdatePanel>
code-behind:
protected void cbIsComplete_CheckChanged(object sender, EventArgs e)
{
string cText = ((GridViewRow)(((System.Web.UI.WebControls.CheckBox)sender).Parent.Parent)).Cells[0].Text;
int selRowIndex = ((GridViewRow)(((System.Web.UI.WebControls.CheckBox)sender).Parent.Parent)).RowIndex;
System.Web.UI.WebControls.CheckBox cb = (System.Web.UI.WebControls.CheckBox)gvSubTasks.Rows[selRowIndex].FindControl("cbIsComplete");
using (SqlConnection oCon = new SqlConnection(gloString))
{
using (SqlCommand qSave = new SqlCommand())
{
qSave.Connection = oCon;
qSave.CommandType = CommandType.Text;
qSave.CommandText = @""; //update command
try
{
oCon.Open();
qSave.ExecuteNonQuery();
}
catch (SqlException ce)
{
}
finally
{
oCon.Close();
}
}
}
upSubasks.Update();
}
What I am looking to do is when the upSubtasks.Update() executes the checkbox to be disabled in "checked" state (the value is 1) but that is not happening. I can uncheck the checkbox once the UpdatePanel does the updating.
Aucun commentaire:
Enregistrer un commentaire