【问题标题】:ASP.net Gridview Paging doesin't work inside UpdatePanelASP.net Gridview 分页在 UpdatePanel 中不起作用
【发布时间】:2011-06-15 16:22:19
【问题描述】:

尽管类似的问题已经被问过很多次了,但问题仍然没有得到解决。这是问题: 我有一个GridView,它包含在标签容器AJAX 控件中,该控件本身位于UpdatePanel 中。 Gridview 效果很好,并且其相应的方法被准确触发,但是当我在单击第 2 页后启用paging(例如)时,GridView 会自行隐藏。这是我的 PageIndexChanging() 方法:

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
    GridView1.PageIndex = e.NewPageIndex;        
    GridView1.DataBind();
    UpdatePanel2.Update();        
}

为什么分页会导致GridView 停止正常工作?我能做什么?

【问题讨论】:

标签: asp.net ajax gridview updatepanel paging


【解决方案1】:

解决方案是,每次更改页面索引时,您都应该重新填充用于填充 gridview 的数据集。通过这种方式,您可以确保在每个由 gridview 页码触发的单独回发中,都会填充结果。

【讨论】:

    【解决方案2】:

    我刚刚尝试了上面的代码。我有同样的问题,现在它工作得很好。

    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) 
    { 
        GridView1.PageIndex = e.NewPageIndex;         
        GridView1.DataBind(); 
        //  UpdatePanel2.Update();   <-- Remove this line from your code.
    } 
    

    我在更新面板中有 GridView。您是否也在 .aspx 文件中编写了事件 PageIndexChanging?

    希望这会有所帮助。

    【讨论】:

      【解决方案3】:

      进一步研究:

      http://msdn.microsoft.com/en-us/library/cc295545.aspx

      与 UpdatePanel 控件不兼容的控件

      以下 ASP.NET 控件与部分页面更新不兼容,因此不适合在 UpdatePanel 控件中工作:

      • GridView 和 DetailsView 控件的 EnableSortingAndPagingCallbacks 属性设置为 true 时。默认为假。

      【讨论】:

        【解决方案4】:

        我遇到了同样的问题,将 updatepanel 属性 UpdateMode="Conditional" 更改为 UpdateMode="Always" 并设置属性 ChildrenAsTriggers="true" 为我解决了这个问题。

        【讨论】:

          【解决方案5】:

          为此,您必须在页面索引更改事件中重新设置数据源。性能会降低,但您可以这样做。

          protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
          {
              GridView1.DataSource = ;//Set again the datasource
              GridView1.PageIndex = e.NewPageIndex;
              GridView1.DataBind();
              UpdatePanel2.Update();
          }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 2019-12-03
            • 2023-03-27
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多