Asp: Use of the GridView control, aspgridview Control
Use asp: GridView to display a statistical table
Cs style:
<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 Control
<Asp: GridView ID = "GridView1" runat = "server" AutoGenerateColumns = "false"
Width = "100%" border = "0" CssClass = "gridview_m"
OnRowCreated = "SmartGridView1_RowCreated">
<Columns>
<Asp: BoundField DataField = "Camp No.">
<HeaderStyle Width = "60px"/>
<ItemStyle HorizontalAlign = "Center"/>
</Asp: BoundField>
<Asp: BoundField DataField = "Camp name">
<HeaderStyle Width = "30px"/>
<ItemStyle HorizontalAlign = "Center"/>
</Asp: BoundField>
<Asp: BoundField DataField = "country">
<HeaderStyle Width = "60px"/>
<ItemStyle HorizontalAlign = "Center"/>
</Asp: BoundField>
<Asp: BoundField DataField = "number of groups this year">
<HeaderStyle Width = "60px"/>
<ItemStyle HorizontalAlign = "Center"/>
</Asp: BoundField>
<Asp: BoundField DataField = "expected number of students this year">
<HeaderStyle Width = "60px"/>
<ItemStyle HorizontalAlign = "Center"/>
</Asp: BoundField>
<Asp: BoundField DataField = "Number of warehouse receiving users this year">
<HeaderStyle Width = "60px"/>
<ItemStyle HorizontalAlign = "Center"/>
</Asp: BoundField>
<Asp: BoundField DataField = "number of groups last year">
<HeaderStyle Width = "60px"/>
<ItemStyle HorizontalAlign = "Center"/>
</Asp: BoundField>
<Asp: BoundField DataField = "predicted last year">
<HeaderStyle Width = "60px"/>
<ItemStyle HorizontalAlign = "Center"/>
</Asp: BoundField>
<Asp: BoundField DataField = "Number of students in the Database last year">
<HeaderStyle Width = "60px"/>
<ItemStyle HorizontalAlign = "Center"/>
</Asp: BoundField>
<Asp: BoundField DataField = "Booking growth">
<HeaderStyle Width = "60px"/>
<ItemStyle HorizontalAlign = "Center"/>
</Asp: BoundField>
<Asp: BoundField DataField = "number of incoming users">
<HeaderStyle Width = "60px"/>
<ItemStyle HorizontalAlign = "Center"/>
</Asp: BoundField>
<Asp: BoundField DataField = "Reservation growth rate">
<HeaderStyle Width = "60px"/>
<ItemStyle HorizontalAlign = "Center"/>
</Asp: BoundField>
<Asp: BoundField DataField = "Number of warehouse receiving growth">
<HeaderStyle Width = "60px"/>
<ItemStyle HorizontalAlign = "Center"/>
</Asp: BoundField>
</Columns>
</Asp: GridView>
Cs Program
Public void SmartGridView1_RowCreated (object sender, GridViewRowEventArgs e)
{
If (e. Row. RowType = DataControlRowType. Header)
{
TableCellCollection header = e. Row. Cells;
Header. Clear ();
String headtxt = "Camp No. </th> <th rowspan = '2' style = 'text-align: center; background: # fb855d'; width: 250px; '> camp name </th> <th rowspan = '2' style = 'text-align: center; background: #2dcc70; width: 50px; '> country </th> ";
Headtxt + = "<th colspan = '3' style = 'text-align: center; background: #02dab1; width: 100px; '> <span style = 'text-align: center; color: #000000 '> this year </span> </th> ";
Headtxt + = "<th colspan = '3' style = 'text-align: center; background: # f8c049; width: 100px; '> <span style = 'text-align: center; color: #000000 '> last year </span> </th> ";
Headtxt + = "<th colspan = '4' style = 'text-align: center; background: # fb855d; width: 100px; '> <span style = 'text-align: center; color: #000000 '> growth during the same period </span> </th> </tr> <tr> ";
Headtxt + = "<th style = 'text-align: center; background: #02dab1 '> <span style = 'color: #333333 '> Number of groups </span> </th> <th style = 'text-align: center; background: #02dab1'> <span style = 'color: #333333 '> expected users </span> </th> <th style = 'text-align: center; background: #02dab1'> <span style = 'color: #333333 '> Number of warehouse receiving users </span> </th> ";
Headtxt + = "<th style = 'text-align: center; background: # f8c049 '> <span style = 'color: #333333 '> Number of groups </span> </th> <th style = 'text-align: center; background: # f8c049'> <span style = 'color: #333333 '> expected users </span> </th> <th style = 'text-align: center; background: # f8c049'> <span style = 'color: #333333 '> Number of warehouse receiving users </span> </th> ";
Headtxt + = "<th style = 'text-align: center; background: # fb855d'> expected growth </th> <th style = 'text-align: center; background: # fb855d '> Number of warehouse receiving increases </th> <th style = 'text-align: center; background: # fb855d '> expected growth rate </th> <th style = 'text-align: center; background: # fb855d '> warehouse receiving growth rate </th> </tr> <tr> ";
Headtxt + = "</tr> ";
TableHeaderCell cell = new TableHeaderCell ();
Cell. Attributes. Add ("rowspan", "2"); // cross-row
Cell. Attributes. Add ("style", "text-align: center; background: #35bef1 ");
Cell. Attributes. Add ("width", "50px ");
Cell. Text = headtxt;
Header. Add (cell );
}
}