国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > .NET > 正文

Asp.net_Table控件の單元格縱向合并示例

2020-01-17 23:47:59
字體:
供稿:網(wǎng)友

業(yè)務(wù)需要,動(dòng)態(tài)生成表,同一列中數(shù)據(jù)相同的單元格需要合并。
解決方案,創(chuàng)建Table控件處理類,代碼如下:

復(fù)制代碼 代碼如下:

/// <summary>表格控件相關(guān)操作類
/// </summary>
public static class aspTable
{
/// <summary>合并行
/// </summary>
/// <remarks>版權(quán)信息:http://www.qqextra.com,http://t.qq.com/ls_man,http://blog.csdn.net/ls_man 2013-06-21 14:20:36</remarks>
/// <param name="tbl">Table</param>
/// <param name="startRow">起始行</param>
/// <param name="endRow">結(jié)束行</param>
/// <param name="colIndex">要合并的列索引</param>
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;
//內(nèi)容是否相同
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;
}
}
//合并最后一項(xiàng)
tbl.Rows[spanRow].Cells[colIndex].RowSpan = countRowSpan;
}
/// <summary>合并行,支持多列
/// </summary>
/// <remarks><SPAN style="FONT-FAMILY: Arial, Helvetica, sans-serif">版權(quán)信息:http://www.qqextra.com,http://t.qq.com/ls_man,http://blog.csdn.net/ls_man</SPAN><SPAN style="FONT-FAMILY: Arial, Helvetica, sans-serif"> 2013-06-21 15:24:34</remarks></SPAN>
/// <param name="tbl">Table</param>
/// <param name="startRow">起始行</param>
/// <param name="endRow">結(jié)束行</param>
/// <param name="colIndex">要合并的列索引</param>
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]);
}
}
}

需要注意的幾點(diǎn),起始行一般設(shè)置為1,因?yàn)?是標(biāo)題行;結(jié)束行一般設(shè)置為Table的總行數(shù)-1即可(最后一行)。

發(fā)表評(píng)論 共有條評(píng)論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 射洪县| 黄冈市| 房山区| 河间市| 丰县| 巴里| 高淳县| 嫩江县| 丰原市| 全南县| 苏尼特右旗| 木兰县| 余干县| 新乡县| 建始县| 琼中| 申扎县| 古田县| 公安县| 台北市| 咸阳市| 茌平县| 剑川县| 响水县| 邛崃市| 丘北县| 北川| 南开区| 海兴县| 合阳县| 博乐市| 扎赉特旗| 阿坝县| 城市| 和政县| 连平县| 镇赉县| 涡阳县| 安龙县| 丹凤县| 乌什县|