Add TBody and THead elements in GridView

讓ASP.NET所開發出來的網頁資料表格也能具有符合W3C HTML table tag 規格 , 在你的GV控制項加入 GridView1_PreRender 事件就可以了 , 這樣子所呈現出來的資料結構就具有
, and elements 了 , 搞定!

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;
}

}


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

沒有留言: