Friday, February 20, 2009

GridView Create THeader and TBody

protected void Page_Load(object sender, EventArgs e)
{
//Add data to the GridView
GridView1.DataSource = SQLHelper.ExecuteDataset("Data Source=SERVER;Initial
Catalog=DBName; Uid=sa; PWD=12345678; Connect Timeout=360; pooling=true;
Max PoolSize
=200; ", CommandType.Text, "Select * from TblName");
GridView1.DataBind();

MakeAccessible(GridView1);

}

private void MakeAccessible(GridView grid)
{
//HtmlTextWriterStyle style = new HtmlTextWriterStyle();
//TableRow tr = new TableRow();
////tr.Style.Add(HtmlTextWriterStyle
//tr.Style.Add(style ,
if (grid.Rows.Count > 0)
{
//This replaces with and adds the scope attribute
grid.UseAccessibleHeader = true;

//This will add the and elements
grid.HeaderRow.TableSection = TableRowSection.TableHeader;
//grid.HeaderStyle.AddAttributesToRender(


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


Another Way/

No comments: