View code using system; using system. collections. generic; using system. LINQ; using system. web; using system. web. UI. webcontrols; // <summary> /// gridviewprocess combines griedviews /// </Summary> public class gridviewprocess {public gridviewprocess () {// todo: add the constructor logic here //} # region merge cells merge all columns in a row // <summary> // merge rows (cells) with the same information in a row in the gridview) /// </Summary> /// <Param name = "gridview1"> gridview object </param> /// <Param name = "cellnum"> rows to be merged </param> Public static void grouprow (gridview gridview1, int rows) {tablecell oldtc = gridview1.rows [rows]. cells [0]; for (INT I = 1; I <gridview1.rows [rows]. cells. count; I ++) {tablecell Tc = gridview1.rows [rows]. cells [I]; // cells [0] is the column you want to merge if (oldtc. TEXT = tc. text) {TC. visible = false; If (oldtc. columnspan = 0) {oldtc. columnspan = 1;} oldtc. columnspan ++; oldtc. verticalalign = verticalalign. middle ;}else {oldtc = tc ;}}} # endregion # How many columns of a row are merged by Region Merging cells? // <summary> // how many columns of a row are merged by merging cells. /// </Summary> /// <Param name = "gridview1"> gridview id </param> /// <Param name = "rows"> row </param> /// <Param name = "Scol"> Start Column </param> // <Param name = "Ecol"> end column </param> Public static void grouprow (gridview gridview1, int rows, int Scol, int Ecol) {tablecell oldtc = gridview1.rows [rows]. cells [Scol]; for (INT I = 1; I <Ecol-Scol; I ++) {tablecell Tc = gridview1.rows [rows]. cells [I + Scol]; // cells [0] is the column TC you want to merge. visible = false; If (oldtc. columnspan = 0) {oldtc. columnspan = 1;} oldtc. columnspan ++; oldtc. verticalalign = verticalalign. middle ;}# endregion # region merge cells merge all rows in a column // <summary> // merge rows with the same information in a column in the gridview (cell) /// </Summary> /// <Param name = "gridview1"> </param> /// <Param name = "cellnum"> </param> Public static void groupcol (gridview gridview1, int Cols) {If (gridview1.rows. count <1 | Cols> gridview1.rows [0]. cells. count-1) {return;} tablecell oldtc = gridview1.rows [0]. cells [Cols]; for (INT I = 1; I <gridview1.rows. count; I ++) {tablecell Tc = gridview1.rows [I]. cells [Cols]; If (oldtc. TEXT = tc. text) {TC. visible = false; If (oldtc. rowspan = 0) {oldtc. rowspan = 1;} oldtc. rowspan ++; oldtc. verticalalign = verticalalign. middle ;}else {oldtc = tc ;}}} # endregion # merge region cells to merge certain rows in a column // <summary> // merge cells to merge certain rows in a column /// </Summary> // /<Param name = "gridview1"> gridview id </param> // <Param name = "cellnum"> column </param> /// <Param name = "srow "> Start row </param> /// <Param name =" erow "> end column </param> Public static void groupcol (gridview gridview1, int cols, int srow, int erow) {If (gridview1.rows. count <1 | Cols> gridview1.columns. count-1) {return;} tablecell oldtc = gridview1.rows [srow]. cells [Cols]; for (INT I = 1; I <erow-srow; I ++) {tablecell Tc = gridview1.rows [srow + I]. cells [Cols]; TC. visible = false; If (oldtc. rowspan = 0) {oldtc. rowspan = 1;} oldtc. rowspan ++; oldtc. verticalalign = verticalalign. middle ;}# endregion}