Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gridview inside Update panel PageIndex not maintained on button click

Tags:

c#

asp.net

I have a gridview inside update panel and a button on whose click gridview is binded.

<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>

When I click on Change button , gridview is rebinded but page index number is reset to 1 irrespective of on which page I was when button was clicked.

1 2 3 4

How to maintain page number while using this Update panel control.

like image 223
Mudassir Hasan Avatar asked Jan 29 '26 01:01

Mudassir Hasan


1 Answers

You can put the page number in ViewState and update it just before you rebind it. just before rebinding the GridView assign the page number from the ViewState

like image 114
Adil Avatar answered Jan 30 '26 15:01

Adil