【问题标题】:Applying Page Indexing or Pagination to GridView将页面索引或分页应用于 GridView
【发布时间】:2012-11-19 14:28:20
【问题描述】:

我有一个带有数组列表的ICollectionLabCollection。这个数组列表包含另一个类LabEntity。 LabEntity 具有 LabID、LabName 等属性。

我正在将 ICollection 类绑定到 gridview:

LabCollection objLabCollection = new LabCollection();
gridview.DataSource = objlabCollection;
gridview.DataBind();

我想将页面索引/分页应用于gridview,我该如何使用上述方法。

【问题讨论】:

  • 你的问题不够清楚。你想要什么页面索引?你试过什么?
  • 我的意思是gridview中的页面索引。之前我使用数据表绑定到网格视图并使用数据视图进行事件页面索引更改以在网格视图中实现页面索引。现在我使用上面提到的 Icollection 类作为数据源。我想知道页面索引如何应用于事件使用 Icollection 为 gridview 更改页面索引。

标签: c# asp.net gridview pagination


【解决方案1】:

在 gridview 标记中将AllowPaging=True 设置为PageSize=x,将x 替换为任何数字,例如10。

标记:

<asp:GridView ID="gridview" AllowPaging="true" PageSize="10" OnPageIndexChanging="gridview_PageIndexChanging" runat="server" /> 

代码隐藏:

protected void gridview_PageIndexChanging(object sender, GridViewPageEventArgs e){
    FillGrid();
    gridview.PageIndex = e.NewPageIndex;
    gridview.DataBind();
}

【讨论】:

    猜你喜欢
    • 2019-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-02
    相关资源
    最近更新 更多