Navigation

Search

Categories

On this page

and tags in Gridview
Including

Archive

Blogroll

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

RSS 2.0 | Atom 1.0 | CDF

Send mail to the author(s) E-mail

Total Posts: 245
This Year: 51
This Month: 0
This Week: 0
Comments: 0

Sign In
Pick a theme:

# Friday, May 28, 2010
Friday, May 28, 2010 2:13:20 AM (GMT Daylight Time, UTC+01:00) ( Gridview )


By default the Gridview does not use these tags to create its table and often times you will need these elements in client-side scripts:

<table id="myTable"> 
<thead> 
<tr>     
<th>Last Name</th>     
<th>First Name</th>     
<th>Email</th>     
<th>Due</th>     
<tbody> 
<tr>     
<td>Smith</td>     
<td>John</td>     
<td>jsmith@gmail.com</td>     
<td>$50.00</td>     
</tr>
</tobdy>
</table> 
The easiest way to achieve is is to use the page Pre_Render event:
protected void gv_PreRender(object sender, EventArgs e)
{

   if (gv.Rows.Count > 0)
   {
      //Replacing <td> with <th> - just in case
      gv.UseAccessibleHeader = true;
      //Adding the <thead> and <tbody> elements
      gv.HeaderRow.TableSection = TableRowSection.TableHeader;

      //This line can be put if you also have footer, it will add <tfoot> element 
      //If you don't have footer, remove it
      gv.FooterRow.TableSection = TableRowSection.TableFooter;
   }

}