C# GridView单元格合并.
生活随笔
收集整理的這篇文章主要介紹了
C# GridView单元格合并.
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
使用
int[] 列索引集合
將第1列的單元格格一樣的數據合并..
GroupRows(GridView1,new int[]{0});
全部代碼
/// <summary>
/// GridView合并行 zgke@sina.com qq:116149
/// </summary>
/// <param name="p_GridView">Grid控件</param>
/// <param name="p_ColumnsIndex">列索引</param>
public static void GroupRows(GridView p_GridView, int[] p_ColumnsIndex)
{
int _Count = p_GridView.Rows.Count;
string[] _TempText = new string[p_ColumnsIndex.Length];
int[] _RowIndex = new int[p_ColumnsIndex.Length];
for (int i = 0; i != _Count; i++)
{
string _CellText = "";
for (int z = 0; z != p_ColumnsIndex.Length; z++)
{
_CellText += p_GridView.Rows[i].Cells[p_ColumnsIndex[z]].Text;
if (_TempText[z] == _CellText)
{
p_GridView.Rows[i].Cells[p_ColumnsIndex[z]].Visible = false;
p_GridView.Rows[_RowIndex[z]].Cells[p_ColumnsIndex[z]].RowSpan++;
}
else
{
_RowIndex[z] = i;
_TempText[z] = _CellText;
p_GridView.Rows[_RowIndex[z]].Cells[p_ColumnsIndex[z]].RowSpan = 1;
}
}
}
}
int[] 列索引集合
將第1列的單元格格一樣的數據合并..
GroupRows(GridView1,new int[]{0});
全部代碼
/// <summary>
/// GridView合并行 zgke@sina.com qq:116149
/// </summary>
/// <param name="p_GridView">Grid控件</param>
/// <param name="p_ColumnsIndex">列索引</param>
public static void GroupRows(GridView p_GridView, int[] p_ColumnsIndex)
{
int _Count = p_GridView.Rows.Count;
string[] _TempText = new string[p_ColumnsIndex.Length];
int[] _RowIndex = new int[p_ColumnsIndex.Length];
for (int i = 0; i != _Count; i++)
{
string _CellText = "";
for (int z = 0; z != p_ColumnsIndex.Length; z++)
{
_CellText += p_GridView.Rows[i].Cells[p_ColumnsIndex[z]].Text;
if (_TempText[z] == _CellText)
{
p_GridView.Rows[i].Cells[p_ColumnsIndex[z]].Visible = false;
p_GridView.Rows[_RowIndex[z]].Cells[p_ColumnsIndex[z]].RowSpan++;
}
else
{
_RowIndex[z] = i;
_TempText[z] = _CellText;
p_GridView.Rows[_RowIndex[z]].Cells[p_ColumnsIndex[z]].RowSpan = 1;
}
}
}
}
轉載于:https://www.cnblogs.com/jxsoft/archive/2011/06/22/2087447.html
總結
以上是生活随笔為你收集整理的C# GridView单元格合并.的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 7/7 第7篇 函数名与函数指针
- 下一篇: 熟悉 ASP.NET MVC 类