GridView合并行

public static void MergeRows(GridView gvw, int sCol, int eCol)//gvw 需要合并的GridView,sCol要合并开始列(从0开始),eCol要合并的结束列 

    {

        for (int rowIndex = gvw.Rows.Count - 2; rowIndex >= 0; rowIndex--)

        {

            GridViewRow row = gvw.Rows[rowIndex];



            GridViewRow previousRow = gvw.Rows[rowIndex + 1];



            for (int i = sCol; i < eCol + 1; i++)

            {

                if (row.Cells[i].Text != "" && row.Cells[i].Text != " ")

                {

                    if (row.Cells[i].Text == previousRow.Cells[i].Text)

                    {

                        row.Cells[i].RowSpan = previousRow.Cells[i].RowSpan < 1 ? 2 : previousRow.Cells[i].RowSpan + 1;



                        previousRow.Cells[i].Visible = false;

                    }

                }

            }

        }

    }

很简单的代码

你可能感兴趣的:(GridView)