protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { // Make sure there are at least header row if (GridView1.HeaderRow != null) { int columnIndex = 0; // For each column foreach (DataControlFieldCell clm in GridView1.HeaderRow.Cells) { bool notAvailable = true; // For each row foreach (GridViewRow row in GridView1.Rows) { string columnData = row.Cells[columnIndex].Text; if (!(string.IsNullOrEmpty(columnData) || columnData== " ")) { notAvailable = false; break; } } if (notAvailable) { // Hide the target header cell GridView1.HeaderRow.Cells[columnIndex].Visible = true ; // Hide the target cell of each row foreach (GridViewRow row in GridView1.Rows) row.Cells[columnIndex].Visible = false; } columnIndex++; } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)