求教:DataTable多层表头及合并

il525li 2012-03-27 08:51:35
有这样一个数据集

id name starttime endtime state
1 aa 10:00 11:00 0
1 aa 11:10 11:50 1
1 aa 12:02 13:31 0
2 bb 1:20 3:22 0
2 bb 5:30 8:03 1
3 cc 22:00 2:20 1



想把这个数据集下的这个表做成如下格式的

id name one two three
time state time state time state
1 aa 10:00-11:00 0 11:10-11:50 1 12:02-13:31 0
2 bb 1:20-3:22 0 5:30-8:03 1 null
3 cc 22:00-2:20 1 null null


不知道大家能看明白吗??
怎么样实现啊 求高手帮帮忙啊!!!
...全文
944 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
段传涛 2012-03-27
  • 打赏
  • 举报
回复
//合并表头
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
//switch (e.Row.RowType)
//{
// case DataControlRowType.Header:
// //第一行表头
// TableCellCollection tcHeader = e.Row.Cells;
// tcHeader.Clear();
// ////tcHeader.Add(new TableHeaderCell());
// ////tcHeader[0].Attributes.Add("rowspan", "3"); //跨Row
// ////tcHeader[0].Attributes.Add("bgcolor", "white");
// ////tcHeader[0].Text = "";
// ////tcHeader.Add(new TableHeaderCell());
// ////tcHeader[1].Attributes.Add("bgcolor", "Red");
// ////tcHeader[1].Attributes.Add("colspan", "10"); //跨Column
// ////tcHeader[1].Text = "全部信息</th></tr><tr>";

// //第二行表头
// tcHeader.Add(new TableHeaderCell());
// tcHeader[0].Attributes.Add("bgcolor", "DarkSeaGreen");
// tcHeader[0].Attributes.Add("colspan", "1");
// tcHeader[0].Attributes.Add("width", "30");
// tcHeader[0].Text = "序号";
// tcHeader.Add(new TableHeaderCell());
// tcHeader[1].Attributes.Add("bgcolor", "LightSteelBlue");
// tcHeader[1].Attributes.Add("colspan", "1");
// tcHeader[1].Attributes.Add("width", "180");
// tcHeader[1].Text = "PART NUMBER";
// tcHeader.Add(new TableHeaderCell());
// tcHeader[2].Attributes.Add("bgcolor", "DarkSeaGreen");
// tcHeader[2].Attributes.Add("colspan", "3");
// tcHeader[2].Attributes.Add("width", "165");
// tcHeader[2].Text = "IN STOCK";
// tcHeader.Add(new TableHeaderCell());
// tcHeader[3].Attributes.Add("bgcolor", "LightSteelBlue");
// tcHeader[3].Attributes.Add("colspan", "6");
// tcHeader[3].Attributes.Add("width", "420");
// tcHeader[3].Text = "order</th></tr><tr>";

// //第三行表头
// tcHeader.Add(new TableHeaderCell());
// tcHeader[4].Attributes.Add("bgcolor", "Khaki");
// tcHeader[4].Text = "序号";
// tcHeader.Add(new TableHeaderCell());
// tcHeader[5].Attributes.Add("bgcolor", "Khaki");
// tcHeader[5].Text = "PART NUMBER";
// tcHeader.Add(new TableHeaderCell());
// tcHeader[6].Attributes.Add("bgcolor", "Khaki");
// tcHeader[6].Text = "NIB";
// tcHeader.Add(new TableHeaderCell());
// tcHeader[7].Attributes.Add("bgcolor", "Khaki");
// tcHeader[7].Text = "NOB";
// tcHeader.Add(new TableHeaderCell());
// tcHeader[8].Attributes.Add("bgcolor", "Khaki");
// tcHeader[8].Text = "COVERED";
// tcHeader.Add(new TableHeaderCell());
// tcHeader[9].Attributes.Add("bgcolor", "Khaki");
// tcHeader[9].Text = "1-2WEEKS";
// tcHeader.Add(new TableHeaderCell());
// tcHeader[10].Attributes.Add("bgcolor", "Khaki");
// tcHeader[10].Text = "2-3WEEKS";
// tcHeader.Add(new TableHeaderCell());
// tcHeader[11].Attributes.Add("bgcolor", "Khaki");
// tcHeader[11].Text = "3-4WEEKS";
// tcHeader.Add(new TableHeaderCell());
// tcHeader[12].Attributes.Add("bgcolor", "Khaki");
// tcHeader[12].Text = "4-6WEEKS";
// tcHeader.Add(new TableHeaderCell());
// tcHeader[13].Attributes.Add("bgcolor", "Khaki");
// tcHeader[13].Text = "6-8WEEKS";
// tcHeader.Add(new TableHeaderCell());
// tcHeader[14].Attributes.Add("bgcolor", "Khaki");
// tcHeader[14].Text = "操作";
// break;
//}
}
段传涛 2012-03-27
  • 打赏
  • 举报
回复
我是用在gridiew里 合并的。代码很简单, 复制进去可以。
如果绑定是列名 写参数就可以
bwangel 2012-03-27
  • 打赏
  • 举报
回复
那要看你用的那个rdlc报表支不支持多表头了。
这和DataTable本身一点关系都没有。

数据层和表现层是有区别的。这个概念要分清楚。
il525li 2012-03-27
  • 打赏
  • 举报
回复
有人帮帮忙吗
il525li 2012-03-27
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 fangxinggood 的回复:]

不是 DataTable 合并,而是 DataGridView 合并。

http://www.cnblogs.com/neuhawk/archive/2006/09/28/517507.html
[/Quote]

这不是绑在DataGridView里的 是放在rdlc报表上
EnForGrass 2012-03-27
  • 打赏
  • 举报
回复
[Quote=引用楼主 il525li 的回复:]
有这样一个数据集
C# code

id name starttime endtime state
1 aa 10:00 11:00 0
1 aa 11:10 11:50 1
1 aa 12:02 13:31 0
2 bb 1:20 3:22 0
2 bb ……
[/Quote]
我也觉得,你只有在数据控件里去处理
参考
http://www.cnblogs.com/peterzb/archive/2009/05/29/1491891.html
机器人 2012-03-27
  • 打赏
  • 举报
回复
不是 DataTable 合并,而是 DataGridView 合并。

http://www.cnblogs.com/neuhawk/archive/2006/09/28/517507.html

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧