您现在的位置是:网站首页> 编程资料编程资料
Asp.net_Table控件の单元格纵向合并示例_实用技巧_
2023-05-25
389人已围观
简介 Asp.net_Table控件の单元格纵向合并示例_实用技巧_
业务需要,动态生成表,同一列中数据相同的单元格需要合并。
解决方案,创建Table控件处理类,代码如下:
复制代码 代码如下:
///
///
public static class aspTable
{
///
///
///
/// Table
/// 起始行
/// 结束行
/// 要合并的列索引
public static void SetRowSpan(Table tbl, int startRow, int endRow, int colIndex)
{
int countRowSpan = 0;
int spanRow = startRow;
string spanText = tbl.Rows[startRow].Cells[colIndex].Text;
for (int rowIndex = startRow; rowIndex <= endRow; rowIndex++)
{
string currentText = tbl.Rows[rowIndex].Cells[colIndex].Text;
//内容是否相同
if (currentText == spanText)
{
countRowSpan++;
//移除被合并的单元格
if (rowIndex != spanRow)
{
tbl.Rows[rowIndex].Cells.RemoveAt(colIndex);
}
}
else
{
//合并
tbl.Rows[spanRow].Cells[colIndex].RowSpan = countRowSpan;
//从此行再向下比较(重置)
countRowSpan = 0;
spanRow = rowIndex--;
spanText = currentText;
}
}
//合并最后一项
tbl.Rows[spanRow].Cells[colIndex].RowSpan = countRowSpan;
}
///
///
///
/// Table
/// 起始行
/// 结束行
/// 要合并的列索引
public static void SetRowSpans(Table tbl, int startRow, int endRow, params int[] colIndexs)
{
ArrayList al = new ArrayList(colIndexs);
al.Sort();
for (int i = al.Count - 1; i >= 0; i--)
{
SetRowSpan(tbl, startRow, endRow, (int)al[i]);
}
}
}
需要注意的几点,起始行一般设置为1,因为0是标题行;结束行一般设置为Table的总行数-1即可(最后一行)。
您可能感兴趣的文章:
- datalist,Repeater和Gridview的区别分析
- asp.net中让Repeater和GridView支持DataPager分页
- repeater、gridview 在绑定时判断判断显示不同的行样式或文本
- ASP.NET MVC4之js css文件合并功能(3)
- Asp.net程序优化js、css实现合并与压缩的方法
- ASP.NET GridView 实现课程表显示(动态合并单元格)实现步骤
- asp.net中GridView和DataGrid相同列合并实现代码
- asp.net中rdlc 合并行的方法
- asp.net 合并GridView中某列相同信息的行(单元格)
- ASP.NET中GridView和Repeater重复数据如何合并
相关内容
- asp.net利用NamingContainer属性获取GridView行号的方法_实用技巧_
- asp.net得到本机数据库实例的两种方法代码_实用技巧_
- .net连接oracle的3种实现方法_实用技巧_
- Asp.net中判断一个session是否合法的方法_实用技巧_
- 后缀为 ashx 与 axd 的文件区别浅析_实用技巧_
- asp.net 数据绑定的实例代码_实用技巧_
- asp.Net JS取母板页控件值的简单方法_实用技巧_
- .net 获取浏览器Cookie(包括HttpOnly)实例分享_实用技巧_
- asp.net C#生成和解析二维码的实例代码_实用技巧_
- asp.net无法加载oci.dll等错误的解决方法_实用技巧_
