asp.net中DataGrid双行跨列跨行复杂表头设计心得!
来源:互联网 发布:电脑淘宝网如何看微淘 编辑:程序博客网 时间:2024/04/29 03:15
一、DataGrid的属性设置
1. AllowPaging: true
2. PageStyle->Position: TopAndBottom
3. 可选:PageStyle->HorizonAlign: Center(使文本居中显示)
4. 可选:ItemStyle->HorizonAlign: Center(使文本居中显示)
二、代码部分
1.首先,使DataGrid绑定数据库中某个表,例如:
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)
{
SqlConnection myConn=new SqlConnection("server=localhost;uid=sa;pwd=sa;database=db_test");
SqlDataAdapter da=new SqlDataAdapter("Select * from 个人",myConn);
DataSet ds=new DataSet();
da.Fill(ds,"gr");
dgGeRen.DataSource=ds.Tables["gr"].DefaultView;
dgGeRen.DataBind();
}
2.为DataGrid添加ItemCreated事件的处理函数、
3.为了判断DataGrid中的两个(上下)Pager的位置,我们可以使用一个全局变量来判断。
定义一个全局变量 private int m_CreatePageTimes = 0;
4.为DataGrid的ItemCreated事件的处理函数添加内容,如下:
private void dgGeRen_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
switch(e.Item.ItemType)
{
//case(ListItemType.Pager):
case ListItemType.Pager:
{
if(m_CreatePageTimes == 0)
{
DataGridItem row=(DataGridItem)e.Item;
row.Cells.Clear();
//row.BackColor=Color.Navy; //背景色
//row.ForeColor=Color.Red; //前景色
row.HorizontalAlign=HorizontalAlign.Center;//使文本居中显示
TableCell cell0=new TableCell();
cell0.RowSpan=2;
cell0.Controls.Add(new LiteralControl("姓名"));
TableCell cell1=new TableCell();
cell1.ColumnSpan=2; //默认的ColumnSpan值为1
cell1.Text="住房地址信息";
//也可如此:cell1.Controls.Add(new LiteralControl("住房地址信息"));
//TableCell cell2=new TableCell();
//cell2.Controls.Add(new LiteralControl(""));
TableCell cell2=new TableCell();
cell2.RowSpan=2;
cell2.Text="出生日期";
row.Cells.Add(cell0);
row.Cells.Add(cell1);
row.Cells.Add(cell2);
m_CreatePageTimes++;
}
break;
}
case ListItemType.Header:
{
DataGridItem head=(DataGridItem)e.Item;
head.Cells.Clear();
//head.VerticalAlign=VerticalAlign.Middle;
//head.HorizontalAlign=HorizontalAlign.Center;
//TableCell cell00=new TableCell();
//cell00.RowSpan=2;
//cell00.Text="姓名";
TableCell cell01=new TableCell();
cell01.Text="楼号";
TableCell cell02=new TableCell();
cell02.Text="房号";
//TableCell cell03=new TableCell();
//cell03.Text="出生日期";
//head.Cells.Add(cell00);
head.Cells.Add(cell01);
head.Cells.Add(cell02);
//head.Cells.Add(cell03);
break;
}
}
}
三、最后效果如下图:
http://dotnet.mblogger.cn/upimgs/dotnet.mblogger.cn/Mark_Lee/2005-2/2005_228786.jpg
四、望大家指点!
- asp.net中DataGrid双行跨列跨行复杂表头设计心得!
- asp.net中DataGrid双行跨列表头设计心得!
- ASP.NET中固定DataGrid的表头
- ASP.NET 中 GridView 的合并表头单元格,并且双行标题
- Jquery easyUI-DataGrid 复杂表头设计方法
- [转载]DataGrid中创建复杂表头方法
- DataGrid中创建复杂表头方法
- DataGrid中创建复杂表头(转载)
- EasyUI中DataGrid复杂表头案例
- asp.net的DataGrid的多层表头
- asp.net datagrid实现多层表头
- asp.net的DataGrid的多层表头
- asp.net的DataGrid的多层表头
- jquery-easyui中为DataGrid创建复杂表头
- ASP.NET 2.0中GridView无限层复杂表头的实现
- ASP.NET 2.0中GridView无限层复杂表头的实现
- ASP.NET 2.0中GridView无限层复杂表头的实现
- ASP.NET 2.0中GridView无限层复杂表头的实现
- 经理人必看的十个管理网站
- QuickServer开发指南(7)- 使用和定制日志
- 管理工作中的“七种浪费”
- X86平台操作系统概览[转自C6H5NO2的后院]
- take me to your heart
- asp.net中DataGrid双行跨列跨行复杂表头设计心得!
- MMS(Multimedia Message System)支持的mdia总结
- thumbs.db文件详解及去除方法
- JDOM 介绍及使用指南
- 什么是软件缺陷
- Jdom 读写例子
- 创建一个忽略 重复值的索引 SQLserver 中隐藏的存储过程
- C#版ftp方法实现类库代码
- Adobe Acrobat Professional 7.0