Search This Blog

Friday, June 25, 2010

GridView To Table

private System.Web.UI.WebControls.Table ConvertGridViewToTable(GridView gridView)
{
bool allowPaging = gridView.AllowPaging;
gridView.AllowPaging = false;
gridView.DataBind();
// Create a table to contain the grid
System.Web.UI.WebControls.Table tableControl = new System.Web.UI.WebControls.Table();

// include the gridline settings
tableControl.GridLines = gridView.GridLines;

// add the header row to the table
if (gridView.HeaderRow != null)
{
this.PrepareControlForExport(gridView.HeaderRow);
tableControl.Rows.Add(gridView.HeaderRow);
}

// add each of the data rows to the table
foreach (GridViewRow rowInGrid in gridView.Rows)
{
this.PrepareControlForExport(rowInGrid);
tableControl.Rows.Add(rowInGrid);
}

// add the footer row to the table
if (gridView.FooterRow != null)
{
this.PrepareControlForExport(gridView.FooterRow);
tableControl.Rows.Add(gridView.FooterRow);
}

gridView.AllowPaging = allowPaging;
gridView.DataBind();

return tableControl;
}

No comments:

Post a Comment