C# GridView的分页问题

C# GridView的分页问题,c#,asp.net,gridview,paging,C#,Asp.net,Gridview,Paging,我有一个asp.net网页,带有GridView <asp:GridView ID="grid_view" runat="server" AllowPaging="True" AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" Grid

我有一个asp.net网页,带有
GridView

<asp:GridView ID="grid_view" runat="server" AllowPaging="True" 
    AutoGenerateColumns="False" BackColor="White" BorderColor="#999999" 
    BorderStyle="Solid" BorderWidth="1px" CellPadding="3" ForeColor="Black" 
    GridLines="Vertical">
    <FooterStyle BackColor="#CCCCCC" />
    <Columns>
        <asp:BoundField DataField="adc" HeaderText="Posa No." />
        <asp:BoundField DataField="cde" HeaderText="Unit" />
        <asp:BoundField DataField="efg" HeaderText="User" />
        <asp:BoundField DataField="hj" HeaderText="Posa Date" />
    </Columns>
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
    <SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
    <HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" /> 
    <AlternatingRowStyle BackColor="#CCCCCC" />
</asp:GridView>
我的问题是网格视图已显示,但页面索引不起作用。。。
有人有什么建议吗?

将页面加载代码放在
下!IsPostBack()

原因:每当您单击页码并想查看另一个页面时,页面将被回发,您的
页面加载事件将在
grid\u view\u pageindexchange
之前触发,它将重新绑定gridview,您的事件将丢失,并且不会触发PageIndexChanging事件

其次,更改此选项并查看注释

protected void grid_view_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
  gridfil(); // First bind the gridview 
  grid_view.PageIndex = e.NewPageIndex; // then change the page Index
}

好的,这是穆罕默德·阿赫塔的作品。它在我的主页上。无论如何,非常感谢你。。。
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        con = new SqlConnection(ConfigurationManager.AppSettings["Connection"]);
        gridfil();
    }
}
protected void grid_view_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
  gridfil(); // First bind the gridview 
  grid_view.PageIndex = e.NewPageIndex; // then change the page Index
}