首页 > 学院 > 开发设计 > 正文

C# GridView单元格合并

2019-11-17 04:17:03
字体:
来源:转载
供稿:网友

使用

 
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;
                    }
                }
            }
        }

 


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表