asp:GridView控件的使用

使用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);
            }
        }

 

posted @ 2016-07-26 15:28  ly77461  阅读(3030)  评论(1编辑  收藏  举报