views:

33

answers:

1

I have a GridView that needs to display either x amount of columns from the GridView, or just one column (cell) which will expand to take up the entire row. Deciding which to display is done by checking if that one column is blank or not - if it is blank, display the other cells, or if not, just display that one cell.

How would I go about doing this? I'm using an SqlDataSource to select the contents of the GridView but I'm willing to change this for a more programmatic approach.

Thanks

A: 

I'm not sure if I understand you correctly, but if you want you can build your Table yourself. Then you can control exactly what columns (and what data) to include.

Table table = new Table();
table.GridLines = GridLines.None;
table.CellPadding = 3;
table.CellSpacing = 0;

// add a header
TableHeaderRow header = new TableHeaderRow();
foreach (string header in new string[] { "column1", "column2" }) {
    TableCell cell = new TableCell();
    cell.Text = header;
    header.Cells.Add(cell);
}
// add data
foreach (var rowd in data) {
    TableRow row = new TableRow();
    foreach (string columnData in new string[] { rowd.Column1, rowd.Column2 }){
        TableCell cell = new TableCell();
        cell.Text = columnData;
        row.Cells.Add(cell);
    }
    table.Rows.Add(row);
}
Patrick