• gridview合并相同的行


      #region 方法:合并Gridview行
        /// <summary>
        /// 合并GridView指定行单元格
        /// </summary>
        /// <param name="gv">GridView</param>
        /// <param name="DataKeysName">DataKeys值(以此值为参照,如果此值相同,则将指定的单元格纵向合并)</param>
        /// <param name="rowIndex">要合并的列索引(从0开始)</param>
        protected void AppendGVRow(string DataKeysName, GridView gv, params int[] rowIndex)
        {
            try
            {
                int spanCount = 1;//合并的单元格跨的行数
                int spanNum = -1;//用于确定需合并的起始行

                for (int i = 0; i < rowIndex.Length; i++)
                {
                    for (int j = 0; j < gv.Rows.Count - 1; j++)
                    {
                        if (gv.DataKeys[j][DataKeysName].ToString().Trim() == gv.DataKeys[j + 1][DataKeysName].ToString().Trim())//如果两行的text相同,则合并
                        {
                            if (spanNum == -1)
                            {
                                spanNum = j;//将需要合并的起始行保存到spanNum中
                            }
                            spanCount++;//合并的单元格跨的行数自增1

                            gv.Rows[j + 1].Cells[rowIndex[i]].Visible = false;//将下一行隐藏
                            gv.Rows[spanNum].Cells[rowIndex[i]].RowSpan = spanCount;
                        }
                        else
                        {
                            spanNum = -1;
                            spanCount = 1;
                        }
                    }

                    spanNum = -1;
                    spanCount = 1;
                }
            }
            catch { }
        }
        #endregion

  • 相关阅读:
    C++ vector介绍
    C++string的使用
    关于VS2010error RC2170 : bitmap file res mp1.bmp is not in 3.00 format
    团队项目第一次讨论
    团队项目——铁大树洞个人分析
    第五周学习进度总结
    转发
    android移动端疫情展示
    《构建之法》阅读笔记03
    第四周学习进度总结
  • 原文地址:https://www.cnblogs.com/zlqblog/p/3628102.html
Copyright © 2020-2023  润新知