asp.net - 如何使用 asp.net gridview 进行可移动分页?

标签 asp.net pagination footable

Footable是一个jQuery响应式数据表格插件,当我尝试将它与asp.net GridView组件一起使用时,我在将分页插件附加到表格底部时遇到了问题。

Footable 教程表示将自定义 div 添加到表格的 tfoot 元素

<div class="pagination pagination-centered hide-if-no-paging"></div>

但问题是,如何将这个自定义 html 放在 tfoot 标签内,因为 GridView 自动生成整个 html?你不能简单地将 html 与 asp.net 放在一起,所以我必须制定一个解决方法来生成 tfoot 内的代码。我希望它对将来的人有所帮助,因为我没有找到针对这个特定问题的任何类似的解决方案。

最佳答案

为了解决这个问题,我采用了在这里找到的方法:ASP.NET GridView Newbie Questions About TFOOT and TH

要包含分页所需的自定义 div 标签,结果是:

    protected void onRowCreate(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.Footer)
        {
            int colSpan = e.Row.Cells.Count;

            for (int i = (e.Row.Cells.Count - 1); i >= 1; i -= 1)
            {
                e.Row.Cells.RemoveAt(i);
                e.Row.Cells[0].ColumnSpan = colSpan;
            }

            e.Row.Cells[0].Controls.Add(new LiteralControl("<ul class='pagination pagination-centered hide-if-no-paging'></ul>"));
        }
    }

并在 GridView 声明中的“onRowCreated”中如此调用它

 <asp:GridView ID="gridViewClientes" ShowFooter="true" OnRowCreated="onRowCreate">

不要忘记在 tablePrerender 上调用它,以正确创建 TFOOT:

gridViewClientes.FooterRow.TableSection = TableRowSection.TableFooter;

注意:实际上,我必须将 DIV 元素从可移动示例更改为 UL 元素才能正常工作。

关于asp.net - 如何使用 asp.net gridview 进行可移动分页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24439521/

相关文章:

asp.net - 什么是 SNIReadSyncOverAsync?为什么需要很长时间才能完成?

Django分页重复结果

php - laravel 5.4 分页 links() 方法返回空 html

javascript - 如何使用 jquery-footable 创建过滤器下拉列表?

jquery - 可立足并捕获展开行事件

asp.net - 内置 ASP.NET 4 成员资格提供程序的源代码

c# - 如何在连接字符串中设置用户名和密码以连接到数据库?

c# - 尝试激活 'Microsoft.AspNetCore.Identity.SignInManager` 时无法解析类型 'xxxxx.LoginModel' 的服务

java - 在java中实现分页的最佳方式

javascript - 为什么 footable 的分页不起作用?