背景:我的代码存在的问题如下。在第一次单击按钮时,复选框没有获得选中的复选框,但在第二次单击时,只需获取所有选中的复选框。
以下是代码:
ASPX
此按钮执行流程..
<asp:LinkButton ID="lbDeletePerman" runat="server" OnClick="lbDeletePerman_Click">Yes</asp:LinkButton>
<code><asp:UpdatePanel ID="GVUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:GridView CssClass="da-table" ID="Gv_A" runat="server" DataKeyNames="ID,PatientName" AutoGenerateColumns="false" OnRowCommand="Gv_Appoint_RowCommand">
<Columns>
<asp:TemplateField HeaderStyle-Font-Bold="true" HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="CbE" runat="server" />
<asp:HiddenField ID="hID" Value='<%# Eval("IDENTIFICATION") %>' runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField=""Date" HeaderText="Date" HeaderStyle-Font-Bold="true" HeaderStyle-VerticalAlign="Middle" ItemStyle-VerticalAlign="Middle" />
<asp:BoundField DataField="Cat" HeaderText="Type" HeaderStyle-Font-Bold="true" HeaderStyle-VerticalAlign="Middle" ItemStyle-VerticalAlign="Middle" />
<asp:BoundField DataField="Deleted" HeaderText="Deleted" HeaderStyle-Font-Bold="true" HeaderStyle-VerticalAlign="Middle" ItemStyle-VerticalAlign="Middle" />
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
C#:
protected void lbDeletePerman_Click(object sender, EventArgs e) { try { foreach (GridViewRow rowItem in Gv_Appoint.Rows) { CheckBox CboxElim = (CheckBox)(rowItem.Cells[0].FindControl("CbE")); if (CboxElim.Checked) { LBLT.Text = "Hello"; // NO ENTERING HERE } } GVUpdatePanel.Update(); } catch (Exception er){} }
任何帮助将不胜感激
答案 0 :(得分:0)
lbDeletePerman 需要与 Gv_A 一起位于UpdatePanel内。
<asp:LinkButton ID="lbDeletePerman" runat="server"
OnClick="lbDeletePerman_Click">Yes</asp:LinkButton>
<asp:UpdatePanel ID="GVUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="lbDeletePerman" />
</Triggers>
<asp:GridView>...</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>