当前位置:编程学习 > C#/ASP.NET >>

请教datagridview高人

请问datagridview中如何把headerRow分两行显示?

如:

----------------------------------------------------
            |            个人信息
   姓名      |---------------------------------------        
              |   年龄   |    性别    |    婚否     |
---------------------------------------------------- --------------------编程问答-------------------- 请教了 --------------------编程问答-------------------- 呵呵  很简单的  照着我给你这个写就可以了  
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            switch (e.Row.RowType)
            {
                case DataControlRowType.Header:
                    //第一行表头
                    TableCellCollection tcHeader = e.Row.Cells;
                    tcHeader.Clear();
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[0].Attributes.Add("rowspan", "2"); //跨Row
                    tcHeader[0].Attributes.Add("bgcolor", "#1c67bc");
                    tcHeader[0].Text = "月份";
                    tcHeader.Add(new TableHeaderCell());
                    //tcHeader[1].Attributes.Add("bgcolor", "Red");
                    tcHeader[1].Attributes.Add("colspan", "3"); //跨Column
                    tcHeader[1].Attributes.Add("bgcolor", "#1c67bc");
                    tcHeader[1].Text = "耗油情况总量(单位:元)";
                    tcHeader.Add(new TableHeaderCell());
                    //tcHeader[1].Attributes.Add("bgcolor", "Red");
                    tcHeader[2].Attributes.Add("rowspan", "2");
                    tcHeader[2].Attributes.Add("bgcolor", "#1c67bc");
                    tcHeader[2].Text = "实际耗油总量";
                    tcHeader.Add(new TableHeaderCell());
                    //tcHeader[1].Attributes.Add("bgcolor", "Red");
                    tcHeader[3].Attributes.Add("rowspan", "2");
                    tcHeader[3].Attributes.Add("bgcolor", "#1c67bc");
                    tcHeader[3].Text = "操作</th></tr><tr  style='color:#FFFFFF'>";
                    //第二行表头
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[4].Attributes.Add("bgcolor", "#1c67bc");
                    tcHeader[4].Text = "油耗额定总量";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[5].Attributes.Add("bgcolor", "#1c67bc");
                    tcHeader[5].Text = "节支总量";
                    tcHeader.Add(new TableHeaderCell());
                    tcHeader[6].Attributes.Add("bgcolor", "#1c67bc");
                    tcHeader[6].Text = "超支总量(长途油耗)";

                    break;
            }
        } --------------------编程问答-------------------- 在HeaderRow里面加一个表格,将表格做成楼主想要的样子。 --------------------编程问答-------------------- 着中显示效果用repeater做好点!
   --------------------编程问答-------------------- http://blog.csdn.net/21aspnet/archive/2007/03/25/1540301.aspx

多表头 --------------------编程问答-------------------- 对,这就是一个多表头的问题,
楼上的兄弟们给的方法应该可以解决你的问题了 --------------------编程问答-------------------- 谢谢上述诸位,只不过我现在做的不是webapplication,而是一个formapplication。
只有datagridview控件,没有gridview控件 --------------------编程问答-------------------- 再求教…… --------------------编程问答-------------------- 再求教…… --------------------编程问答-------------------- mark
补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,