哪位大神知道怎么合并吗? 
public static void GroupRows(GridView GridView1, int cellNum, int startNum, int endNum)

解决方案 »

  1.   

    之前在一个项目中用到的方法,希望对你有帮助 
       /// <summary>
        ///  合并列相同内容的单元格,并添加颜色
        /// </summary>
        /// <param name="GridView1"></param>
        /// <param name="cols"></param>
        public static void GroupCol(GridView GridView1, int cols)
        {
            for (int j = 1; j < cols; j++)
            {
                TableCell oldTc = GridView1.Rows[0].Cells[j];
                for (int i = 1; i < GridView1.Rows.Count; i++)
                {
                    TableCell tc = GridView1.Rows[i].Cells[j];
                    if (oldTc.Text == "&nbsp;")
                    {
                        oldTc = tc;
                    }
                    else
                    {                    if (oldTc.Text == tc.Text)
                        {
                            tc.Visible = false;
                            if (oldTc.RowSpan == 0)
                            {
                                oldTc.RowSpan = 1;
                            }
                            oldTc.RowSpan++;
                            oldTc.VerticalAlign = VerticalAlign.Middle;
                            oldTc.Attributes.Add("style", "background-color:#C8BA0D;");
                        }
                        else
                        {
                            oldTc.Attributes.Add("style", "background-color:#C8BA0D;");
                            oldTc = tc;
                        }
                    }
                }
            }
        }