我在网格视图的edititemtamlate 中创建了一个表格。
<asp:TemplateField>
<EditItemTemplate>
<%-- <asp:Panel ID="pnltable" runat="server">--%>
<table border="1px" cellpadding="0px" cellspacing="0px" >
<tr>
<td>
<asp:Label Text="T1" runat="server" ID="Label111"></asp:Label>
</td>
<td>
<asp:Label Text="T2" runat="server" ID="Label112"></asp:Label>
</td>
<td>
<asp:Label Text="T3" runat="server" ID="Label113"></asp:Label>
</td>
<td>
<asp:Label Text="T4" runat="server" ID="Label114"></asp:Label>
</td>
<td>
<asp:Label Text="T5" runat="server" ID="Label115"></asp:Label>
</td>
<td>
<asp:Label Text="T6" runat="server" ID="Label116"></asp:Label>
</td>
<td>
<asp:Label Text="T7" runat="server" ID="Label117"></asp:Label>
</td>
<td>
<asp:Label Text="T8" runat="server" ID="Label118"></asp:Label>
</td>
<td>
<asp:Label Text="T9" runat="server" ID="Label119"></asp:Label>
</td>
<td>
<asp:Label Text="T10" runat="server" ID="Label1110"></asp:Label>
</td>
</tr>
<tr>
<td>
<asp:CheckBox ID="CheckBox11" runat="server" AutoPostBack="true" />
</td>
<td>
<asp:CheckBox ID="CheckBox12" runat="server" AutoPostBack="true" />
</td>
<td>
<asp:CheckBox ID="CheckBox13" runat="server" AutoPostBack="true" />
</td>
<td>
<asp:CheckBox ID="CheckBox14" runat="server" AutoPostBack="true" />
</td>
<td>
<asp:CheckBox ID="CheckBox15" runat="server" AutoPostBack="true" />
</td>
<td>
<asp:CheckBox ID="CheckBox16" runat="server" AutoPostBack="true"/>
</td>
<td>
<asp:CheckBox ID="CheckBox17" runat="server" AutoPostBack="true" />
</td>
<td>
<asp:CheckBox ID="CheckBox18" runat="server" AutoPostBack="true" />
</td>
<td>
<asp:CheckBox ID="CheckBox19" runat="server" AutoPostBack="true" />
</td>
<td>
<asp:CheckBox ID="CheckBox20" runat="server" AutoPostBack="true" />
</td>
</tr>
</table>
<%--</asp:Panel>--%>
</EditItemTemplate>
当用户单击编辑按钮时,该表将显示表中的值。为此,我在 editcommand 中编写了这样的代码,它可以完美运行。
Guid SubscriptionId = (Guid)Subscriptions.DataKeys[e.NewEditIndex].Value;
var s = m.bussinesCollection.BussinesPlanning.GetSingleSubVersionTrueFalse(SubscriptionId);
CheckBox d11 = (CheckBox)Subscriptions.Rows[e.NewEditIndex].FindControl("CheckBox11");
CheckBox d12 = (CheckBox)Subscriptions.Rows[e.NewEditIndex].FindControl("CheckBox12");
CheckBox d13 = (CheckBox)Subscriptions.Rows[e.NewEditIndex].FindControl("CheckBox13");
CheckBox d14 = (CheckBox)Subscriptions.Rows[e.NewEditIndex].FindControl("CheckBox14");
CheckBox d15 = (CheckBox)Subscriptions.Rows[e.NewEditIndex].FindControl("CheckBox15");
CheckBox d16 = (CheckBox)Subscriptions.Rows[e.NewEditIndex].FindControl("CheckBox16");
CheckBox d17 = (CheckBox)Subscriptions.Rows[e.NewEditIndex].FindControl("CheckBox17");
CheckBox d18 = (CheckBox)Subscriptions.Rows[e.NewEditIndex].FindControl("CheckBox18");
CheckBox d19 = (CheckBox)Subscriptions.Rows[e.NewEditIndex].FindControl("CheckBox19");
CheckBox d20 = (CheckBox)Subscriptions.Rows[e.NewEditIndex].FindControl("CheckBox20");
if (d11 != null){
d11.Checked = s.T1.Value;
}
if (d12 != null){
d12.Checked = s.T2.Value;
}
if (d13 != null){
d13.Checked = s.T3.Value;
}
if (d14 != null){
d14.Checked = s.T4.Value;
}
if (d15 != null){
d15.Checked = s.T5.Value;
}
if (d16 != null){
d16.Checked = s.T6.Value;
}
if (d17 != null){
d17.Checked = s.T7.Value;
}
if (d18 != null){
d18.Checked = s.T8.Value;
}
if (d19 != null) {
d19.Checked = s.T9.Value;
}
if (d20 != null){
d20.Checked = s.T10.Value;
}
现在在更新命令中,当我更改复选框值并尝试像在更新命令中的代码中一样更新它时
CheckBox c1 = (CheckBox)(Subscriptions.Rows[e.RowIndex].FindControl("CheckBox11"));
CheckBox c2 = (CheckBox)(Subscriptions.Rows[e.RowIndex].Cells[7].FindControl("CheckBox12"));
CheckBox c3 = (CheckBox)(Subscriptions.Rows[e.RowIndex].FindControl("CheckBox13"));
CheckBox c4 = (CheckBox)(Subscriptions.Rows[e.RowIndex].FindControl("CheckBox14"));
CheckBox c5 = (CheckBox)(Subscriptions.Rows[e.RowIndex].FindControl("CheckBox15"));
CheckBox c6 = (CheckBox)(Subscriptions.Rows[e.RowIndex].FindControl("CheckBox16"));
CheckBox c7 = (CheckBox)(Subscriptions.Rows[e.RowIndex].FindControl("CheckBox17"));
CheckBox c8 = (CheckBox)(Subscriptions.Rows[e.RowIndex].FindControl("CheckBox18"));
CheckBox c9 = (CheckBox)(Subscriptions.Rows[e.RowIndex].FindControl("CheckBox19"));
CheckBox c10 = (CheckBox)(Subscriptions.Rows[e.RowIndex].FindControl("CheckBox20"));
if (c1 != null && c2 != null && c3 != null && c4 != null && c5 != null && c6 != null && c7 != null && c8 != null && c9 != null && c10 != null)
{
m.bussinesCollection.BussinesPlanning.UpdateSubVersionTrueFalseForUpdate(subscriptionID, c1.Checked, c2.Checked, c3.Checked, c4.Checked, c5.Checked, c6.Checked, c7.Checked, c8.Checked, c9.Checked, c10.Checked);
}
但是在这里它没有给出任何错误但是当我调试我显示的代码时,在更新命令中的复选框控制 c1 到 c10 它总是得到值
Checked = false
即使我选中复选框。
所以它以错误的方式更新。
谁能告诉我我错在哪里..?