如何在asp.net gridview中使用jquery tablesorter?

我正在尝试使用tablesorter插件添加gridview的排序。

但是,gridview不会呈现THEAD和TBODY标记。 有没有办法让它添加它们?

资料来源: http : //justgeeks.blogspot.com/2008/09/add-tbody-and-thead-to-gridview.html

视图

  

CS

 protected void GridView1_PreRender(object sender, EventArgs e) { // You only need the following 2 lines of code if you are not // using an ObjectDataSource of SqlDataSource GridView1.DataSource = Sample.GetData(); GridView1.DataBind(); if (GridView1.Rows.Count > 0) { //This replaces  with  and adds the scope attribute GridView1.UseAccessibleHeader = true; //This will add the  and  elements GridView1.HeaderRow.TableSection = TableRowSection.TableHeader; //This adds the  element. //Remove if you don't have a footer row GridView1.FooterRow.TableSection = TableRowSection.TableFooter; } } 

我希望这有帮助!

试试这个 :

 protected void grdDtls_DataBound(object sender, EventArgs e) { if (grdDtls.Rows.Count > 0) { //To render header in accessible format grdDtls.UseAccessibleHeader = true; //Add the  element grdDtls.HeaderRow.TableSection = TableRowSection.TableHeader; //Add the  element grdDtls.FooterRow.TableSection = TableRowSection.TableFooter; if (grdDtls.TopPagerRow != null) { grdDtls.TopPagerRow.TableSection = TableRowSection.TableHeader; } if (grdDtls.BottomPagerRow != null) { grdDtls.BottomPagerRow.TableSection = TableRowSection.TableFooter; } } } 

并在任何填充网格的地方使用以下代码。

 ScriptManager.RegisterStartupScript(this, GetType(), "SortGrid", string.Format("$(function(){{$('#{0}').tablesorter(); }});", grdDtls.ClientID), true);