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/