[Asp.net]GridView之呈现thead 的三种解决方案

引言

项目中使用jquery插件 jquery.tablesorter 对Table进行排序时,GridView Render出来的代码让人心情很不爽。默认的HTML结构是需要<thead /> 标签的。结果导致tablesort不能使用。

 

GridView Render <thead /> 标签吗?

默认情况(vs2008)是不会呈现 <thead /> <tbody /> <tfoot /> 标签。

解决方案

方案一:修改jquery.tablesorter 插件,使其没有thead标签的时候也能使用。(没有实现)

方案二:想方设法让GridView Render 出 <thead /> 等标签,迎合jquery.tablesorter的默认结构。

GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;

在 GridView1 绑定数据源以后,添加上面一行代码,GridView 就可以Render出<thead />标签,问题迎刃而解。

方案三:使用jquey给表格的第一行包装<thead />标签,然后插入到 <tbody />标签前。

          $(function() {
             $("#GriView1 tr:first").wrap("<thead></thead>");
             $("#GriView1 thead").insertBefore("#GriView1 tbody");
             $("#GriView1").tablesorter();
         });

原文地址:https://www.cnblogs.com/JavCof/p/1790204.html