C# 显示每行gridview的标题
我正在使用下面的代码为导出到excel中的gridview设置标题。现在,我需要在导出到excel后为网格的每一行显示此标题 有什么建议我可以做到这一点吗C# 显示每行gridview的标题,c#,asp.net,.net,gridview,export-to-excel,C#,Asp.net,.net,Gridview,Export To Excel,我正在使用下面的代码为导出到excel中的gridview设置标题。现在,我需要在导出到excel后为网格的每一行显示此标题 有什么建议我可以做到这一点吗 if (gv.ID == "GridView1") { TableRow title = new TableRow(); title.BackColor = Color.Cyan; TableCell
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
}
}
}
不是所有的行都有。此外,因为我已经有了列,所以它也会覆盖值,不应该覆盖。此代码在页面上的何处写入。?有一个名为RowDataBound的Gridview事件。此事件会为绑定到Gridview的每一行调用,因此如果您想为每一行运行某些功能,请使用该事件。