Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 显示每行gridview的标题_C#_Asp.net_.net_Gridview_Export To Excel - Fatal编程技术网

C# 显示每行gridview的标题

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

我正在使用下面的代码为导出到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);
            }

在栅格视图的备用行中,使用标题

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的每一行调用,因此如果您想为每一行运行某些功能,请使用该事件。