1

我将AllowPagingGridview 设置为 True,当记录多个页面时,我可以看到页面编号(1,2,..)但是当我单击编号时看不到其他页面(Page2,3,...)并且页面没有不要改变

DataBind()PageIndexChanging事件中使用,但是当我点击数字时,我看不到 GridView

4

2 回答 2

0

调用是不够的GridView.DataBind()。您还必须设置新PageIndex的 in PageIndexChanging

void GridView1_PageIndexChanging(Object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;
    // now get the DataSource(f.e. from database) and assign it
    GridView1.DataBind();
}

另请注意,您不应Page_Load在回发时将 DataSource 绑定到 GridView,而应始终检查IsPostback属性:

如果是后者,请不要将GridViewin绑定page_load到它的 DataSource if Page.IsPostback。

void Page_Load(Object sender, EventArgs e)
{
    if(!Page.IsPostback)
    {
         BindGridView(); // assuming this is the method where you databind the grid
    }
}
于 2012-10-09T11:06:27.877 回答
0

您不能只在 PageIndexChanging 中调用 Databind,您需要像这样设置 GridViews PageIndex

void GrdView_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        GridView x = ((GridView)sender);

        if (e.NewPageIndex > -1 && e.NewPageIndex <= x.PageCount)
        {
            x.PageIndex = e.NewPageIndex;
        }

        GrdView.DataBind();
    }
于 2012-10-09T11:08:58.297 回答