分页NewPageIndex保持不变

时间:2015-06-30 07:06:54

标签: asp.net gridview pagination

我面临一个非常奇怪的问题,asp.net GridView分页。当我第一次单击“下一步”时,它可以正常工作。但是在随后单击“下一步”按钮后,NewPageIndex事件中GridView_PageIndexChanging的值始终为1.当单击“上一步”按钮时,NewPageIndex将返回-1,这也是不正确的。

<asp:GridView ID="GridView1" runat="server" Width="100%"   AutoGenerateColumns="false" 
              BorderWidth="0" CellPadding="3" CellSpacing="1"  
              GridLines="None" OnRowDataBound="GridView1_RowDataBound" PageSize="10" 
              AllowPaging="true" OnPageIndexChanging="GridView1_PageIndexChanging" 
              AllowSorting="true" OnSorting="GridView1_Sorting" OnSorted="GridView1_Sorted" 
              AllowCustomPaging="false">
    <AlternatingRowStyle CssClass="gridAltRowStyle" />
    <HeaderStyle CssClass="gridHeaderStyle" />
    <RowStyle CssClass="gridRowStyle" />
    <FooterStyle CssClass="gridFooterStyle" />
    <PagerSettings Mode="NextPreviousFirstLast" Position="TopAndBottom"  Visible="true" 
                   FirstPageImageUrl="~/images/first.png" NextPageImageUrl="~/images/next.png" 
                   PreviousPageImageUrl="~/images/prev.png" LastPageImageUrl="~/images/last.png" />
    <PagerStyle ForeColor="Brown" Font-Names="Verdana" Font-Size="XX-Small"HorizontalAlign="Right" VerticalAlign="Bottom" /> 
    <Columns> 
    </Columns>
</asp:GridView>


protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 
{
    this.GridView1.PageIndex = e.NewPageIndex;
    this.GridView1.DataSource = this.GetDataSource();
    this.GridView1.DataBind(); 
}

protected void Page_Load(object sender, System.EventArgs e)
{
   if (!ParentPage.IsControlPostBack)
   {
       this.GridView1.PageIndex = 0;
    this.GridView1.DataSource = this.GetDataSource();
    this.GridView1.DataBind();
   }
}

0 个答案:

没有答案