Asp.net merges rows (cells) with the same information in a column in the GridView)

Source: Internet
Author: User


Solution ):
Copy codeThe Code is as follows:
/// <Summary>
/// Merge rows with the same information in a column in the GridView (cell)
/// </Summary>
/// <Param name = "GridView1"> GridView </param>
/// <Param name = "cellNum"> column number </param>
Public static void GroupRows (GridView GridView1, int cellNum)
{
Int I = 0, rowSpanNum = 1;
While (I <GridView1.Rows. Count-1)
{
GridViewRow gvr = GridView1.Rows [I];

For (++ I; I <GridView1.Rows. Count; I ++)
{
GridViewRow gvrNext = GridView1.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 = GridView1.Rows. Count-1)
{
Gvr. Cells [cellNum]. RowSpan = rowSpanNum;
}
}
}
}


If you want to merge multiple columns, you can modify them as appropriate.
A complete life should be forgiveness, tolerance, waiting, and love!

Related Article

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.