views:

9

answers:

1

I'm trying to add sorting of a gridview using the tablesorter plugin.

However, the gridview does not render the THEAD and TBODY tags. Is there a way to get it to add them?

A: 

Source: http://justgeeks.blogspot.com/2008/09/add-tbody-and-thead-to-gridview.html

view

<asp:GridView ID="GridView1" runat="server" 
    OnPreRender="GridView1_PreRender">
</asp:GridView>

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 <td> with <th> and adds the scope attribute
      GridView1.UseAccessibleHeader = true;

      //This will add the <thead> and <tbody> elements
      GridView1.HeaderRow.TableSection = TableRowSection.TableHeader;

      //This adds the <tfoot> element. 
      //Remove if you don't have a footer row
      GridView1.FooterRow.TableSection = TableRowSection.TableFooter;
   }

}

I hope this help!

Mouhannad
Didn't need to put this in to a pre_render method, setting those params during the page load worked as well.
chris
yeah i know, i just thought i'll share the same code; it would be easy to figure out what to do from it :)
Mouhannad