Asp.net gridview merge Cells

Source: Internet
Author: User
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}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.