打印本文 打印本文 关闭窗口 关闭窗口
Asp.Net下的DataGrid的多层表头(网友贴)
作者:武汉SEO闵涛  文章来源:敏韬网  点击数727  更新时间:2009/4/23 10:41:00  文章录入:mintao  责任编辑:mintao

Asp.Net下的DataGrid的多层表头       

[ 来自:csdn ]

先看下表:
seover="this.style.cursor=''''hand'''';" style="CURSOR: hand" onclick="window.open(this.src);" height="110" alt="按此在新窗口打开图片" src="/Article/UploadFiles/200904/2009042310410079.gif" width="492" onload="javascript:DrawImage(this);" border="0"/>

  实际上Asp.Net下的DataGrid只不过是一个HtmlTable,只不过在HtmlTable的基础上添加了很多属性、方法,纳入ViewState机制,来生成、控制它;有了这一点认识,事情就很好办了:

  我们可以在属性生成器中可以定义列的表头,它实际上只不过是在列之间插入了“</td><td>”的html标记,如此而已;因此根据上面的例子,可以在第3列的header里输入以下内容“</td></tr><TR><TD>北京</TD><TD>上海</TD><TD>深圳</TD></TR>”,这时你会发现2层表头就出现了:

seover="this.style.cursor=''''hand'''';" style="CURSOR: hand" onclick="window.open(this.src);" height="119" alt="按此在新窗口打开图片" src="/Article/UploadFiles/200904/2009042310410198.gif" width="490" onload="javascript:DrawImage(this);" border="0"/>

  但是显然还不够,因为我们还需要行、列的合并
  我们可以在DataGrid的ItemDataBound事件中处理


 if(e.Item.ItemType == ListItemType.Header)
{
     e.Item.Cells[0].RowSpan = 2;
     e.Item.Cells[1].ColumnSpan = 3;
     e.Item.Cells[2].Visible = false;
     e.Item.Cells[3].Visible = false;

打印本文 打印本文 关闭窗口 关闭窗口