C# 合并单元格   JS的 也可以!

解决方案 »

  1.   

    1.合并行        /// <summary>
            ///GridView 单元格合并方法
            /// </summary>
            /// <param name="gv">要合并的GridView</param>
            /// <param name="cellNum"></param>
            public static void GetGridViewGroupRows(GridView gv, int cellNum)
            {            int i = 0, rowSpanNum = 1;            while (i < gv.Rows.Count - 1)
                {
                    GridViewRow gvr = gv.Rows[i];                for (++i; i < gv.Rows.Count; i++)
                    {
                        GridViewRow gvrNext = gv.Rows[i];                    if (gvr.Cells[cellNum].Text == gvrNext.Cells[cellNum].Text)
                        {
                            gvrNext.Cells[cellNum].Visible = false;
                            rowSpanNum++;
                        }                    else
                        {
                            gvr.Cells[cellNum].RowSpan = rowSpanNum;
                            rowSpanNum = 1;
                            break;
                        }                    if (i == gv.Rows.Count - 1)
                        {
                            gvr.Cells[cellNum].RowSpan = rowSpanNum;
                        }
                    }
                }
            }2.合并列/// <summary>
            /// 合并单元格
            /// </summary>
            /// <param name="gridView"></param>
            /// <param name="CompareCells">比较基准列</param>
            /// <param name="MergeCells">合并列</param>
            public static void MergeCells(GridView gridView, int[] CompareCells, int[] MergeCells)
            {
                int intSpan = 0;
                int j = 0;
                string[] curCellsValue = new string[CompareCells.Length];
                string[] nextCellsValue = new string[CompareCells.Length];
                for (int i = 0; i < gridView.Rows.Count; i++)
                {
                    intSpan = 1;
                    j = 0;
                    for (int k = 0; k < CompareCells.Length; k++)
                    {
                        curCellsValue[k] = gridView.Rows[i].Cells[CompareCells[k]].Text;
                    }                for (j = i + 1; j < gridView.Rows.Count; j++)
                    {
                        for (int k = 0; k < CompareCells.Length; k++)
                        {
                            nextCellsValue[k] = gridView.Rows[j].Cells[CompareCells[k]].Text;
                        }                    if (IsEqual(curCellsValue, nextCellsValue))
                        {
                            intSpan++;
                            for (int k = 0; k < MergeCells.Length; k++)
                            {
                                gridView.Rows[i].Cells[MergeCells[k]].RowSpan = intSpan;
                                gridView.Rows[j].Cells[MergeCells[k]].Visible = false;
                            }
                        }
                        else
                            break;
                    }
                    i = j - 1;
                }
            }3. /// <summary>
            /// 比较两个数组元素是否相等
            /// </summary>
            /// <param name="arraySource"></param>
            /// <param name="arrayTarget"></param>
            /// <returns></returns>
            protected static bool IsEqual(string[] arraySource, string[] arrayTarget)
            {
                int arrayLen = arraySource.Length;
                bool isEqual = true;
                for (int i = 0; i < arrayLen; i++)
                {
                    if (string.Compare(arraySource[i], arrayTarget[i], true) == 0)
                        continue;
                    else
                        return false;
                }
                return isEqual;
            }
      

  2.   

    farpoint组件可以实现的http://wenku.baidu.com/view/44c338a1284ac850ad024201.html(说明文档)http://download.csdn.net/down/2464043/libra6956(软件)
      

  3.   

    有没有table合并的 !!!!
      

  4.   

    单元格合并和table有什么关系呢