Friday, September 12, 2008

GridView - Create THeader and TBody

This is useful when we are applying sytle.




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

GenerateHeaders(GridView1);
}

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

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


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

No comments: