GridView双层表头应该怎么做?
现在我把我刚写好的单层表头贴一下,就是很普通的GridView+dataTable方式。
前台
<asp:GridView ID="gv_EmployeeP" runat="server" AutoGenerateColumns="False" OnRowDataBound="gv_OrderInfo_RowDataBound"> <Columns> <asp:BoundField DataField="客服" HeaderText="客服" ReadOnly="True"> <HeaderStyle Font-Bold="True" /> <ItemStyle Width="40px" /> </asp:BoundField> <asp:BoundField DataField="今日总共" HeaderText="总共" ReadOnly="True"> <HeaderStyle Font-Bold="True" /> <ItemStyle Width="40px" /> </asp:BoundField> <asp:BoundField DataField="今日已到" HeaderText="已到" ReadOnly="True"> <HeaderStyle Font-Bold="True" /> <ItemStyle Width="40px" /> </asp:BoundField> <asp:BoundField DataField="今日未到" HeaderText="未到" ReadOnly="True"> <HeaderStyle Font-Bold="True" /> <ItemStyle Width="40px" /> </asp:BoundField> <asp:BoundField DataField="昨日总共" HeaderText="总共" ReadOnly="True"> <HeaderStyle Font-Bold="True" /> <ItemStyle Width="40px" /> </asp:BoundField> <asp:BoundField DataField="昨日已到" HeaderText="已到" ReadOnly="True"> <HeaderStyle Font-Bold="True" /> <ItemStyle Width="40px" /> </asp:BoundField> <asp:BoundField DataField="昨日未到" HeaderText="未到" ReadOnly="True"> <HeaderStyle Font-Bold="True" /> <ItemStyle Width="40px" /> </asp:BoundField> <asp:BoundField DataField="昨日总共" HeaderText="总共" ReadOnly="True"> <HeaderStyle Font-Bold="True" /> <ItemStyle Width="40px" /> </asp:BoundField> </Columns> </asp:GridView>
private DataTable OneSelfData(DataTable _dt) { DataTable dt = new DataTable("Table_OneSelf"); dt.Columns.Add("客服", System.Type.GetType("System.String")); dt.Columns.Add("今日总共", System.Type.GetType("System.Int32")); dt.Columns.Add("今日已到", System.Type.GetType("System.Int32")); dt.Columns.Add("今日未到", System.Type.GetType("System.Int32")); dt.Columns.Add("昨日总共", System.Type.GetType("System.Int32")); //。。省略 DataRow dr = dt.NewRow(); //中间代码省略 dt.Rows.Add(dr); return dt; } 我想实现的效果是->上前台代码中的第2~4列添加一个“今日”列,在最后“三列”头部加一个“昨日”列。
在网上搜了一些,自己也正在研究中。。。发个帖子的目的是希望高手给点快速完成这个功能的方案(比如最好不要破坏我原有的后台代码结构)
[解决办法]
帮顶了,顺便学习
[解决办法]
把这6个列改成<HeaderStyle Font-Bold="True" Height="50px" VerticalAlign="Bottom" />
把文字靠下,然后贴个div上去,就可以了。
[解决办法]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm4.aspx.cs" Inherits="WebTest.WebForm4" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title></head><body> <form id="form1" runat="server"> <asp:GridView ID="gv_EmployeeP" runat="server" AutoGenerateColumns="False" OnRowDataBound="gv_OrderInfo_RowDataBound" onrowcreated="gv_EmployeeP_RowCreated"> <Columns> <asp:BoundField DataField="客服" HeaderText="客服" ReadOnly="True"> <HeaderStyle Font-Bold="True" /> <ItemStyle Width="40px" /> </asp:BoundField> <asp:BoundField DataField="今日总共" HeaderText="总共" ReadOnly="True"> <HeaderStyle Font-Bold="True" /> <ItemStyle Width="40px" /> </asp:BoundField> <asp:BoundField DataField="今日已到" HeaderText="已到" ReadOnly="True"> <HeaderStyle Font-Bold="True" /> <ItemStyle Width="40px" /> </asp:BoundField> <asp:BoundField DataField="今日未到" HeaderText="未到" ReadOnly="True"> <HeaderStyle Font-Bold="True" /> <ItemStyle Width="40px" /> </asp:BoundField> <asp:BoundField DataField="昨日总共" HeaderText="总共" ReadOnly="True"> <HeaderStyle Font-Bold="True" /> <ItemStyle Width="40px" /> </asp:BoundField> <asp:BoundField DataField="昨日已到" HeaderText="已到" ReadOnly="True"> <HeaderStyle Font-Bold="True" /> <ItemStyle Width="40px" /> </asp:BoundField> <asp:BoundField DataField="昨日未到" HeaderText="未到" ReadOnly="True"> <HeaderStyle Font-Bold="True" /> <ItemStyle Width="40px" /> </asp:BoundField> <asp:BoundField DataField="昨日总共" HeaderText="总共" ReadOnly="True"> <HeaderStyle Font-Bold="True" /> <ItemStyle Width="40px" /> </asp:BoundField> </Columns> </asp:GridView> </form></body></html>