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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM