使用
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;
}
}
}
}
新闻热点
疑难解答