0

我在 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 没有记录,我应该怎么做才能合并标题?

4

1 回答 1

0

将代码从OnRowCreated事件移动到Load事件Window/Control/Page

于 2013-01-09T05:34:36.580 回答