[英]CheckBox gets checked in the second click in c# GridView
Background : The problem I have with my code is the following. 背景 :我的代码存在以下问题。 Upon the first click of a button the checkbox doesn't get the checked checkboxes, but on the second click just get all the checked checkboxes.
第一次单击按钮时,该复选框不会得到选中的复选框,但是在第二次单击时,只会得到所有选中的复选框。
Here is the code: 这是代码:
ASPX ASPX
This button execute the process.. 此按钮执行过程。
<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#: 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){} }
Any help would be appreciated 任何帮助,将不胜感激
lbDeletePerman needs to be inside UpdatePanel together with Gv_A . lbDeletePerman需要与Gv_A一起位于UpdatePanel中。
Or use the AsyncPostBackTrigger 或使用AsyncPostBackTrigger
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.