asp.net GridView多行表头的实现,合并表头
protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.Header)
{
TableCellCollection tcHeader = e.Row.Cells;
//获取表头所在行的所有单元格 //清除自动生成的表头
tcHeader.Clear(); //新添加的第一个表头单元格, 设置为合并7个列, 从而形成一行.
tcHeader.Add(new TableHeaderCell());
tcHeader[0].ColumnSpan = 7;
tcHeader[0].Text = "测试多行合并表头</th></tr><tr>";
//</th>表示当前单元格结束, </tr>表示本行结束, <tr>另起新一行 关键点 //添加第二个表头单元格, 设置为合并两行.
tcHeader.Add(new TableHeaderCell());
tcHeader[1].RowSpan = 2;
tcHeader[1].Text = "表头";
tcHeader.Add(new TableHeaderCell());
tcHeader[2].Text = "表头1"; tcHeader.Add(new TableHeaderCell());
tcHeader[3].ColumnSpan = 2;
tcHeader[3].Text = "表头2"; tcHeader.Add(new TableHeaderCell());
tcHeader[4].ColumnSpan = 3;
tcHeader[4].Text = "表头3</th></tr><tr>";
//第二行的所有的单元格添加完成, 换行</th></tr><tr> //添加第三行所有的单元格
tcHeader.Add(new TableHeaderCell());
tcHeader[5].Text = "表头1-1"; tcHeader.Add(new TableHeaderCell());
tcHeader[6].Text = "表头2-1"; tcHeader.Add(new TableHeaderCell());
tcHeader[7].Text = "表头2-2"; tcHeader.Add(new TableHeaderCell());
tcHeader[8].Text = "表头3-1"; tcHeader.Add(new TableHeaderCell());
tcHeader[9].Text = "表头3-2"; tcHeader.Add(new TableHeaderCell());
tcHeader[10].Text = "表头3-3</th></tr><tr>"; } }
第二种方法
protected void GridView1_RowCreated( object sender, GridViewRowEventArgs e )
{ if (e.Row.RowType == DataControlRowType.Header)
{
//创建一个GridViewRow,相当于表格的 TR 一行
GridViewRow rowHeader = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
string HeaderBackColor = "#EDEDED";
rowHeader.BackColor = System.Drawing.ColorTranslator.FromHtml(HeaderBackColor); //实现确定要显示的表头样式,也可以通过计算生成 // <tr>
// <td rowspan='2'>关键单元格</td>
// <td colspan='2'>表头文字</td>
// <td colspan='2'>表头文字</td>
// <td>表头文字</td>
// </tr>
// <tr bgcolor='#FFF'>
// <td colspan='2'>表头文字</td>
// <td rowspan='2'>表头文字</td>
// <td colspan='2'>表头文字</td>
// </tr>
// <tr bgcolor='#FFF'>
// <td>表头文字</td>
// <td>表头文字</td>
// <td>表头文字</td>
// <td>表头文字</td>
// <td>表头文字</td>";
// </tr>
// 上面的样式可以设置斜线 Literal newCells = new Literal();
newCells.Text = @"表头文字1</th>
<th colspan='2'>表头文字2</th>
<th colspan='2'>表头文字3</th>
<th>表头文字4</th>
</tr>
<tr bgcolor='" + HeaderBackColor + "'>";
newCells.Text += @"
<th colspan='2'>表头文字5</th>
<th rowspan='2'>表头文字6</th>
<th colspan='2'>表头文字7</th>
</tr>
<tr bgcolor='" + HeaderBackColor + "'>";
newCells.Text += @"
<th>表头文字8</th>
<th>表头文字9</th>
<th>表头文字10</th>
<th>表头文字11</th>
<th>表头文字12"; TableCellCollection cells = e.Row.Cells;
TableHeaderCell headerCell = new TableHeaderCell();
//下面的属性设置与 <td rowspan='2'>关键单元格</td> 要一致
headerCell.RowSpan = 2;
headerCell.Controls.Add(newCells);
rowHeader.Cells.Add(headerCell); rowHeader.Cells.Add(headerCell);
rowHeader.Visible = true; //添加到 GridView1
GridView1.Controls[0].Controls.AddAt(0, rowHeader);
}
}
asp.net GridView多行表头的实现,合并表头的更多相关文章
- 如何让Gridview在没有数据的时候显示表头(asp.net)
原文:如何让Gridview在没有数据的时候显示表头(asp.net) 1.前言 当对GridView控件进行数据绑定时,如果绑定的记录为空,网页上就不显示GridView,造成页面部分空白,页面布局 ...
- Asp.net GridView 72般绝技
快速预览:GridView无代码分页排序GridView选中,编辑,取消,删除GridView正反双向排序GridView和下拉菜单DropDownList结合GridView和CheckBox结合鼠 ...
- GridView/DataGrid行单击和双击事件实现代码_.Net教程
功能: 单击选中行,双击打开详细页面 说明:单击事件(onclick)使用了 setTimeout 延迟,根据实际需要修改延迟时间 ;当双击时,通过全局变量 dbl_click 来取消单击事件的响应 ...
- GRIDVIEW多行多列合并单元格(合并列)
GitHub项目地址:https://github.com/mingceng/merge-gridviewcell 去年的时候,我写了两篇文章: GridView多行多列合并单元格(完整代码和例子) ...
- 【DevExpress v17.2新功能预告】增强ASP.NET GridView的功能
在下一个主要版本v17.2中,我们将为DevExpress ASP.NET GridView添加一些优秀的新功能.在本文中为大家介绍的所有功能都可用于 GridView的ASP.NET WebForm ...
- DEV express 对Gridview某行的元素赋值
1:获取选中的行某列的值 string colValue= this.gridView1.GetRowCellValue(this.gridView1.FocusedRowHandle, this.g ...
- gridview的行选择的一个问题
我想实现这样一个效果:单击gridview的行内任意地方都可以选择该行(就是行内复选框被选中),同时修改该行的背景色.当再次单击行内任意地方又可以取消选择.另外,当单击选择行内复选框时,我希望可以选择 ...
- asp.net导出excel-一行代码实现excel、xml、pdf、word、html、csv等7种格式文件导出功能而且美观-SNF快速开发平台
分享: 腾讯微博 新浪微博 搜狐微博 网易微博 腾讯朋友 百度贴吧 豆瓣 QQ好友 人人网 作者:王春天 原文地址:http://www.cnblogs.com/spring_ ...
- ASP.new GridView获取隐藏列值的几种方法
解决方法: 原文来自:http://www.tzwhx.com/NewShow/newBodyShow/控件_32933.html 作者:lerit 1.隐藏列前获取数据 看这样一个例子(以下均以此 ...
随机推荐
- 计算概论(A)/基础编程练习2(8题)/2:计算书费
#include<stdio.h> int main() { // 声明与初始化 ; // k组测试数据的总费用 double s[k]; // 单价表 double price[]= { ...
- 08:Python数据分析之pandas学习
1.1 数据结构介绍 参考博客:http://www.cnblogs.com/nxld/p/6058591.html 1.pandas介绍 1. 在pandas中有两类非常重要的数据结构,即序列Ser ...
- 20145327《网络对抗》——注入shellcode并执行和Return-to-libc攻击深入
20145327<网络对抗>--注入shellcode并执行 准备一段Shellcode 老师的shellcode:\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68 ...
- 20165211 2017-2018-2 《Java程序设计》第3周学习总结
20165211 2017-2018-2 <Java程序设计>第3周学习总结 教材学习内容总结 本周,我学习了书本上第四章的内容,以下是我整理的主要知识. 第四章 类与对象 编程语言的几个 ...
- Educational Codeforces Round 21 Problem F (Codeforces 808F) - 最小割 - 二分答案
Digital collectible card games have become very popular recently. So Vova decided to try one of thes ...
- noip 2012 提高组 day2 部分题解
这道题有多种解法,我用的是扩展欧几里得算法求到的答案 #include<iostream> #include<fstream> #include<cstdio> u ...
- mips32和x86下的大小端模式判定
一.背景 1.1 mips32搭载32bit vxworks操作系统 1.2 x86搭载64bit windows10操作系统 二.大小端模式判定前的准备 2.1 先要知道各种架构上各种整型数占据的b ...
- 全球变暖|2018年蓝桥杯B组题解析第九题-fishers
标题:全球变暖 你有一张某海域NxN像素的照片,"."表示海洋."#"表示陆地,如下所示: ....... .##.... .##.... ....##. .. ...
- Educational Codeforces Round 56 (Rated for Div. 2)
涨rating啦.. 不过话说为什么有这么多数据结构题啊,难道是中国人出的? A - Dice Rolling 傻逼题,可以用一个三加一堆二或者用一堆二,那就直接.. #include<cstd ...
- BZOJ3296: [USACO2011 Open] Learning Languages 并查集
Description 农夫约翰的N(2 <= N<=10,000)头奶牛,编号为1.. N,一共会流利地使用M(1<= M <=30,000)种语言,编号从1 .. M., ...