显示每行网格视图的标题

本文关键字:标题 视图 网格 显示 | 更新日期: 2023-09-27 18:01:10

我正在使用下面的代码为导出到excel的网格视图设置标题。现在,我需要在导出到excel后,为网格的每一行显示这个标题。

有什么建议我可以做到这一点吗?

            if (gv.ID == "GridView1")
            {
                TableRow title = new TableRow();
                title.BackColor = Color.Cyan;
                TableCell titlecell = new TableCell();
                titlecell.ColumnSpan = 3;
                Label lbl = new Label();
                lbl.Text = "XYZ REPORT 2014";
                titlecell.Controls.Add(lbl);
                title.Cells.Add(titlecell);
                table.Rows.Add(title);
            }
            if (gv.ID == "GridView2")
            {
                TableRow title = new TableRow();
                title.BackColor = Color.Yellow;
                TableCell titlecell = new TableCell();
                titlecell.ColumnSpan = 4;
                Label lbl = new Label();
                lbl.Text = "XYZ REPORT 2015";
                titlecell.Controls.Add(lbl);
                title.Cells.Add(titlecell);
                table.Rows.Add(title);
            }

显示每行网格视图的标题

在网格视图的交替行中使用标题

protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        if (e.Row.RowState == DataControlRowState.Alternate)
        {
            // Ur header row here
        }
    }
}