使用asp:GridView显示一个统计的表格

cs样式:

<style>
        table.gridview_m
        {
            border-collapse: collapse;
            border: solid 1px #93c2f1;
            width: 100%;
            font-size: 9pt;
            line-height: 24px;
        }
        table.gridview_m td, th
        {
            border-collapse: collapse;
            border: solid 1px #93c2f1;
            font-size: 9pt;
        }
        tr.gridview_row td
        {
            text-align: center;
            font-size: 9pt;
            color: #444;
        }
        input
        {
            border: 1px solid #999;
            padding-left: 3px;
        }
    </style>

aspx控件

<asp:GridView ID="GridView1" runat="server"  AutoGenerateColumns="false"
                     Width="100%" border="0" CssClass="gridview_m"
                    OnRowCreated="SmartGridView1_RowCreated">
                    <Columns>
                      <asp:BoundField  DataField="营地编号">
                        <HeaderStyle Width="60px" />
                            <ItemStyle HorizontalAlign="Center" />
                     </asp:BoundField>
                      <asp:BoundField DataField="营地名称">
                            <HeaderStyle Width="30px" />
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                        <asp:BoundField DataField="国家">
                            <HeaderStyle Width="60px" />
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                         <asp:BoundField DataField="本年团个数">
                            <HeaderStyle Width="60px" />
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                        <asp:BoundField DataField="本年预计人数">
                            <HeaderStyle Width="60px" />
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                        <asp:BoundField DataField="本年入库人数">
                            <HeaderStyle Width="60px" />
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                         <asp:BoundField DataField="去年团个数">
                            <HeaderStyle Width="60px" />
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                        <asp:BoundField DataField="去年预计人数">
                            <HeaderStyle Width="60px" />
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                        <asp:BoundField DataField="去年入库人数">
                            <HeaderStyle Width="60px" />
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                         <asp:BoundField DataField="预订增长数">
                            <HeaderStyle Width="60px" />
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                        <asp:BoundField DataField="入库人数增长数">
                            <HeaderStyle Width="60px" />
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                         <asp:BoundField DataField="预订增长率">
                            <HeaderStyle Width="60px" />
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                        <asp:BoundField DataField="入库人数增长率">
                            <HeaderStyle Width="60px" />
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                        
                    </Columns>
                </asp:GridView>

cs程序

public void SmartGridView1_RowCreated(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.Header)
            {
                TableCellCollection header = e.Row.Cells;
                header.Clear();
                string headtxt = "营地编号</th><th rowspan='2' style='text-align:center;background:#fb855d';width:250px;'>营地名称</th><th rowspan='2' style='text-align:center;background:#2dcc70;width:50px;'>国家</th>";
                headtxt += "<th colspan='3' style='text-align:center;background:#02dab1;width:100px;'><span style='text-align:center;color:#000000'>本年</span></th>";
                headtxt += "<th colspan='3' style='text-align:center;background:#f8c049;width:100px;'><span style='text-align:center;color:#000000'>去年</span></th>";
                headtxt += "<th colspan='4' style='text-align:center;background:#fb855d;width:100px;'><span style='text-align:center;color:#000000'>同期增长情况</span></th></tr><tr>";
                headtxt += "<th style='text-align: center;background:#02dab1'><span style='color:#333333'>团个数</span></th><th  style='text-align: center;background:#02dab1'><span style='color:#333333'>预计人数</span></th><th   style='text-align: center;background:#02dab1'><span style='color:#333333'>入库人数</span></th>";
                headtxt += "<th style='text-align: center;background:#f8c049'><span style='color:#333333'>团个数</span></th><th  style='text-align: center;background:#f8c049'><span style='color:#333333'>预计人数</span></th><th   style='text-align: center;background:#f8c049'><span style='color:#333333'>入库人数</span></th>";
                headtxt += "<th  style='text-align: center;background:#fb855d'>预计增长数</th><th style='text-align: center;background:#fb855d'>入库增长数</th><th  style='text-align: center;background:#fb855d'>预计增长率</th><th   style='text-align: center;background:#fb855d'>入库增长率</th></tr><tr>";
                headtxt += "</tr> ";
                TableHeaderCell cell = new TableHeaderCell();
                cell.Attributes.Add("rowspan", "2");  //跨两行

cell.Attributes.Add("style", "text-align:center;background:#35bef1");
                cell.Attributes.Add("width", "50px");
                cell.Text = headtxt;
                header.Add(cell);
            }
        }

asp:GridView控件的使用的更多相关文章

  1. asp:GridView控件使用FindControl方法获取控件的问题

    一.使用带cells的指定列 e.Item.Cells[1].Controls[1]只指定第二列的第二个控件 二.不使用带cells的指定类e.Item.FindControl("ID&qu ...

  2. 027. asp.net中数据绑定控件之 GridView控件

    GridView控件支持下面的功能: 绑定至数据源控件, 如SqlDataSource 内置排序功能 内置更新和删除功能 内置分页功能 内置行选择功能 可以编程方式访问GridView对象模型以动态设 ...

  3. ASP.NET控件GridView的使用& Xml操作注意事项

    更多原创测试技术文章同步更新到微信公众号 :三国测,敬请扫码关注个人的微信号,感谢!   原文链接:http://www.cnblogs.com/zishi/p/6729478.html 文章主要内容 ...

  4. ASP.NET编辑与更新数据(非GridView控件实现)

    Insus.NET在实现<ASP.NET开发,从二层至三层,至面向对象 (5)>http://www.cnblogs.com/insus/p/3880606.html 中,没有把数据编辑与 ...

  5. Asp.Net 控件 GridView

    这两天做的作业都得用到visual studio 越来越发现其功能真心强大 前几天Asp.Net做了个界面增删查改的作业(连接数据库),用到了个组件GridView,感觉很强大 在这里小结一下(这里主 ...

  6. asp.net GridView控件的列属性

    BoundField 默认的数据绑定类型,通常用于显示普通文本 CheckBoxField 显示布尔类型的数据.绑定数据为TRUE时,复选框数据绑定列为选中状态:绑定数据为FALSE时,则显示未选中状 ...

  7. ASP.NET中GridView控件删除数据的两种方法

      今天在用GridView控件时,发现了一个问题,就是使用GridView控件在删除数据时的问题.接下来我们通过模板列方式和CommandField方式删除某条数据讲解下两者之间的区别. 方式一:通 ...

  8. GridView控件中加自动排列序号

    GridView控件中加自动排列序号 为 Gridview 增加一个新的空白列,如下: <asp:BoundField  HeaderText="序号">    < ...

  9. GRIDVIEW 控件

    http://www.cnblogs.com/shanymen/archive/2009/05/22/1486654.html GridView控件是.net里的一个显示数据控件,该控件制作很人性化, ...

随机推荐

  1. windows下Perl如何读取大文件的最后一行(总结)

    Perl中读取文件最后一行的方法很多,比如 (1)将文件读入数组,取最后一个元素 open (FILE,"file.txt") or die "$!"; my ...

  2. 第1章 Flex介绍

    * Flex Flex 是一个高效.免费的开源框架,可用于构建具有表现力的 Web应用程序,这些应用程序利用Adobe Flash Player和Adobe AIR, 可以实现跨浏览器.桌面和操作系统 ...

  3. Android 发布Apk签名

    1.签名的意义 为了保证每个应用程序开发商合法ID,防止部分开放商可能通过使用相同的Package Name来混淆替换已经安装的程序,我们需要对我们发布的APK文件进行唯一签名,保证我们每次发布的版本 ...

  4. session不一定非得要cookie开启才能使用。也可以使用get传递参数

    session不一定非得要cookie开启才能使用.也可以使用get传递参数 可以将session_id();设置为一个常量. define(’s_id‘ ,$_COOKIE['session_nam ...

  5. linux C使用strerror来追查错误信息

    最近工作中有个需求:程序将文件进行处理,然后将处理完毕的文件挪走.我用了rename函数来挪动文件,可是在docker化的环境中,文件却无法挪动.不知道什么原因.现在,对程序进行调整,如果rename ...

  6. 使用Audition录制自己的歌曲

    Audition专为在照相室.广播设备和后期制作设备方面工作的音频和视频专业人员设计,可提供先进的音频混合.编辑.控制和效果处理功能.最多混合 128 个声道,可编辑单个音频文件,创建回路并可使用 4 ...

  7. Struts2 级联下拉框 详解析

    目录(?)[+] 运行环境:myeclipse8.6+jboss5.1+jvm1.6 先看最后目录结构: 直接上源码: complexFormTag.jsp: <%@ page language ...

  8. String类的一些常规方法

    String类 String类常用方法: ①length(): length()       长度    方法** 对比:数组.length      属性** 一般情况下,一个数字,一个字母,一个汉 ...

  9. Spring IOC容器在Web容器中是怎样启动的

    前言 我们一般都知道怎样使用spring来开发web应用后,但对spring的内部实现机制通常不是很明白.这里从源码角度分析下Spring是怎样启动的.在讲spring启动之前,我们先来看看一个web ...

  10. 转:django在生成数据库时常常遇到的问题

    真的很有用! http://blog.csdn.net/pipisorry/article/details/45727309