Gridview内更新面板PageIndex不维护按钮点击

本文关键字:维护 按钮 PageIndex 更新 Gridview | 更新日期: 2023-09-27 18:09:20

我有一个gridview在更新面板和一个按钮上的点击gridview被绑定。

<asp:UpdatePanel runat="server" ID="upPanelPrjSumm" UpdateMode="Conditional">
   <ContentTemplate>
        <asp:GridView ID="gvProjectionSummary" runat="server"           
         AutoGenerateColumns="true"  AllowPaging="true" PageSize="18" 
         OnPageIndexChanging="gvProjectionSummary_PageIndexChanging"
         OnRowDataBound="gvProjectionSummary_RowDataBound" PagerSettings-     
         Mode="Numeric" >
        </asp:GridView>
 <asp:Button runat="server" ID="btnChange" OnClick="btnChange_Click"  
  Text="Change" />
</ContentTemplate>
  <Triggers>
  </Triggers>
</asp:UpdatePanel>

当我点击更改按钮时,gridview被重新绑定,但页面索引号被重置为1,无论我在哪个页面上单击按钮。

1 2 3 4

如何在使用更新面板控件时保持页码

Gridview内更新面板PageIndex不维护按钮点击

您可以将页码放在ViewState中,并在重新绑定之前更新它。在重新绑定GridView之前,从ViewState中分配页码

****试试这个....使用updatepanel的属性****

<asp:UpdatePanel runat="server" ID="upPanelPrjSumm" UpdateMode="Conditional">
<Triggers>
            <asp:PostBackTrigger ControlID="gvProjectionSummary" />
        </Triggers>
 <ContentTemplate>
        <asp:GridView ID="gvProjectionSummary" runat="server"           
         AutoGenerateColumns="true"  AllowPaging="true" PageSize="18" 
         OnPageIndexChanging="gvProjectionSummary_PageIndexChanging"
         OnRowDataBound="gvProjectionSummary_RowDataBound" PagerSettings-     
         Mode="Numeric" >
        </asp:GridView>
 <asp:Button runat="server" ID="btnChange" OnClick="btnChange_Click"  
  Text="Change" />
</ContentTemplate>
</asp:UpdatePanel>