在Gridview中合并标头

时间:2013-01-09 05:26:54

标签: c# gridview

我在Gridview中遇到问题,如果Gridview没有记录,我无法合并标题,但如果Gridview包含记录,则标题正在合并。

以下是我用于合并Gridview

中标题的代码
protected void grdWorkExperience_RowCreated(object sender, GridViewRowEventArgs e)
    {

        if (e.Row.RowType == DataControlRowType.Header)
        {
            GridView oGridView = (GridView)sender;
            GridViewRow oGridViewRow = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Insert);
            TableCell oTableCell = new TableCell();

            oTableCell.Text = string.Empty;
            oTableCell.ColumnSpan = 2;
            oTableCell.BorderColor = System.Drawing.Color.White;
            oGridViewRow.Cells.Add(oTableCell);

            oTableCell = new TableCell();
            oTableCell.Text = "Inclusive Dates(mm/dd/yyyy)";
            oTableCell.ColumnSpan = 2;
            oTableCell.Font.Bold = true;
            oTableCell.Font.Size = 9;
            oTableCell.Font.Name = "Verdana";
            oTableCell.HorizontalAlign = HorizontalAlign.Center;
            oTableCell.BackColor = System.Drawing.Color.FromArgb(0x33, 0x66, 0xCC);
            oTableCell.ForeColor = System.Drawing.Color.White;
            oTableCell.BorderColor = System.Drawing.Color.Gray;
            oGridViewRow.Cells.Add(oTableCell);

            oTableCell = new TableCell();
            oTableCell.BorderColor = System.Drawing.Color.White;
            oTableCell.ColumnSpan = 13;
            oGridViewRow.Cells.Add(oTableCell);

            oGridView.Controls[0].Controls.AddAt(0, oGridViewRow);

        }
    }

我将该功能放在Gridview onRowCreated 事件中

即使Gridview没有记录,我该怎么做才能合并Headers?

1 个答案:

答案 0 :(得分:0)

将代码从OnRowCreated事件移至Load的{​​{1}}事件

相关问题