合并GridView标题列多个标题ASP.NET

时间:2012-02-11 09:10:14

标签: c# asp.net .net gridview

protected void GrdLeaveMaster_RowCreated(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.Header)
    {
        GridView HeaderGrid = (GridView)sender;
        GridViewRow HeaderGridRow =
        new GridViewRow(2, 2, DataControlRowType.EmptyDataRow,
        DataControlRowState.Insert);
        TableCell HeaderCell = new TableCell();
        HeaderCell.Text = "PaidLeave";
        HeaderCell.ColumnSpan = 2;
        HeaderGridRow.Cells.Add(HeaderCell);

        HeaderCell = new TableCell();
        HeaderCell.Text = "accumulated";
        HeaderCell.ColumnSpan = 2;
        HeaderGridRow.Cells.Add(HeaderCell);

        GrdLeaveMaster.Controls[0].Controls.AddAt(0, HeaderGridRow);
    }
}

我希望标题不显示在第二列

中显示的第一列中

enter image description here

1 个答案:

答案 0 :(得分:3)

TableCell HeaderCell = new TableCell();
HeaderCell.Text = "";
HeaderCell.ColumnSpan = 1;
HeaderGridRow.Cells.Add(HeaderCell);

TableCell HeaderCell = new TableCell();
HeaderCell.Text = "PaidLeave";
HeaderCell.ColumnSpan = 1;
HeaderGridRow.Cells.Add(HeaderCell);

希望有所帮助