【发布时间】:2014-05-02 06:23:53
【问题描述】:
我正在使用下面的代码在导出到 excel 时为我的 gridview 设置标题。现在我需要在导出到 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);
}
【问题讨论】:
-
这段代码写在页面的什么地方?
-
有一个名为 RowDataBound 的 Gridview 事件,该事件会为绑定到 gridview 的每一行调用,因此如果您想为每一行运行一些功能,请使用该事件。
标签: c# asp.net .net gridview export-to-excel