【问题标题】:How to loop an entire GridView having AllowPaging attribute set to true?如何循环将 AllowPaging 属性设置为 true 的整个 GridView?
【发布时间】:2012-07-04 09:14:04
【问题描述】:

我在页面中有一个 GridView asp 服务器控件,并且我已将其 AllowPaging 设置为 true。现在,我想循环到整个行,但它只迭代到我定义的 PageSize 的数量。

这是asp代码:

 <asp:GridView ID="gvName" runat="server" AllowPaging="True" PageSize="5" AutoGenerateColumns="True"></asp:GridView>

下面是代码:

 List<string> list = new List<String>();
    for(int x = 0; x <= 9; x++)
    {
        list.Add("Name " + (x + 1).ToString()); 
    }

    gvName.DataSource = list;
    gvName.DataBind();

foreach(GridViewRow row in gvName.Rows)
{
    // gvName.Rows.Count only returns 5 instead of the total number of its record that is 10
}

提前感谢您的任何回答。

【问题讨论】:

  • 你想获取什么?您可以迭代列表以获取该信息。

标签: c# asp.net c#-3.0


【解决方案1】:

这是分页工作方式的一个功能,而不是错误 - 它只为每个页面加载加载 x 行。根据您需要完成的任务,您可以:

  1. 在每次页面加载时循环浏览行(因为您应该只关心可见的行,对吧?)
  2. 使用您的 list 对象或 GridView.DataSource(首先转换为适当的类型)循环浏览实际数据源。

【讨论】:

  • 嗨 dbaseman,我还想考虑页面上不可见的行。无论如何我可以在代码中以编程方式处理它吗?提前致谢。
  • @Jemeel 页面上不存在的 GridView 行还不存在......你想用它们做什么?
  • 我想导航到页面上不存在但看起来不可能的那些行。感谢您对 dbaseman 的支持和回答。
【解决方案2】:

使用网格事件OnRowDataBound 事件对行做所有你想做的工作

获取计数使用: int count = list.Count;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-05-16
    相关资源
    最近更新 更多