public static void gridViewShowHeader(GridView gridView)
{
// Show header row (if none)
Table table = new Table();
if (gridView.Controls.Count != 0) table = (Table)gridView.Controls[0];
if (table.Rows.Count != 0 && ((GridViewRow)table.Rows[0]).RowType
== DataControlRowType.Header) return;
GridViewRow headerRow = new GridViewRow(-1, -1,
DataControlRowType.Header, DataControlRowState.Normal);
for (int i = 0; i < gridView.Columns.Count; i++)
{
TableHeaderCell headerCell = new TableHeaderCell();
headerCell.Text = gridView.Columns[i].HeaderText;
headerRow.Controls.Add(headerCell);
}
table.Rows.AddAt(0, headerRow);
gridView.Controls.Add(table);
}
I have another routine that adds dropdown lists as column filters.
So this routine doesn't just test for an empty gridview, it tests
for a gridview without a header. So this can be run before or after
my gridViewShowFilters routine without a problem.
No comments:
Post a Comment