如何让DataGrid实现如下所示的界面

浩子 2005-07-11 02:17:20
------------------------------------------------
| 湘潭 | 长沙 | 株洲 |
------------------------------------------------
|上午 |下午 |上午 |下午 |上午 |下午 |
------------------------------------------------
|34 |26 |17 |61 |23 |22 |
------------------------------------------------
|24 |43 |52 |23 |25 |41 |
------------------------------------------------
|51 |27 |73 |43 |42 |52 |
------------------------------------------------
...全文
191 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
solsolsol 2005-07-12
  • 打赏
  • 举报
回复
学习一下二楼的方法
浩子 2005-07-12
  • 打赏
  • 举报
回复
如果用Repeater又该如何实现呢?谢谢~!
xifan930 2005-07-11
  • 打赏
  • 举报
回复
标记
zipo 2005-07-11
  • 打赏
  • 举报
回复
不一定非用datagrid
可以换个别的形式
syeerzy 2005-07-11
  • 打赏
  • 举报
回复
建议用Repeater,方便的多,为什么非要DataGrid给自己出难题呢?倒不是说做不到,是有这必要一定得DataGrid吗?
浩子 2005-07-11
  • 打赏
  • 举报
回复
谢谢 goody9807,
不知你有没有试过,我现在的列是动态的,不知道有多少列,
qiangsheng 2005-07-11
  • 打赏
  • 举报
回复
在DATAGRID的上面自己绘制一个表格
sunnystar365 2005-07-11
  • 打赏
  • 举报
回复
用DataList或者Repeater控件吧,DataGrid不可能实现这样的功能吧
goody9807 2005-07-11
  • 打赏
  • 举报
回复
1、DataGrid显示双层表头
http://xml.sz.luohuedu.net/xml/ShowDetail.asp?id=B3F3462D-DC34-41CE-9FEE-6965B2A3D1AD
假设你的DataGrid有三列,现在想将前两列作为"大类1",第三列作为"大类2",现在,你可以在ItemDataBound事件中加入下面的代码:
if (e.Item.ItemType == ListItemType.Header)
{
e.Item.Cells[0].ColumnSpan = 2;
e.Item.Cells[0].Text = "大类1</td><td>大类2</td></tr><tr><td>" + e.Item.Cells[0].Text;
}
用这个方法可以为任意添加新行。
C#
if (e.Item.ItemType == ListItemType.Header)
{
DataGridItem dgi = new DataGridItem(0,-1,ListItemType.Header);
DataGridItem dgi1= new DataGridItem(0,-1,ListItemType.Header);
Table tb = new Table();
tb = (Table)DataGrid1.Controls[0];
tb.Rows.AddAt(0,dgi);
tb.Rows.AddAt(1,dgi1);
TableCell tc = new TableCell();
TableCell tc1 = new TableCell();
TableCell tc2 = new TableCell();
TableCell tc22 = new TableCell();
tc.Text = "ddd";
tc.ColumnSpan = 1;
dgi.Cells.Add(tc);
tc1.Text = "ddd2";
tc1.ColumnSpan = 1;
dgi.Cells.Add(tc1);
tc2.Text = "ddd";
tc2.ColumnSpan = 1;
dgi1.Cells.Add(tc2);
tc22.Text = "ddd2";
tc22.ColumnSpan = 1;
dgi1.Cells.Add(tc22);

}


VB.NET显示双层表头
Dim dgi As DataGridItem
Dim dgi1 As DataGridItem
Dim tc As New TableCell()
Dim tc1 As New TableCell()
Dim tc2 As New TableCell()
Dim tc22 As New TableCell()
Dim tb As New Table()
If (e.Item.ItemType = ListItemType.Header) Then

dgi = New DataGridItem(0, -1, ListItemType.Header)
dgi1 = New DataGridItem(0, -1, ListItemType.Header)
tb = CType(DataGrid1.Controls(0), Table)
tb.Rows.AddAt(0, dgi)
tb.Rows.AddAt(1, dgi1)
tc.Text = "ddd"
tc.ColumnSpan = 1
dgi.Cells.Add(tc)
tc1.Text = "ddd2"
tc1.ColumnSpan = 1
dgi.Cells.Add(tc1)

tc2.Text = "ddd"
tc2.ColumnSpan = 1
dgi1.Cells.Add(tc2)
tc22.Text = "ddd2"
tc22.ColumnSpan = 1
dgi1.Cells.Add(tc22)
End If

62,067

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

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