Merge gridview Cells

Source: Internet
Author: User

/// <Summary>
/// Merge cells with the same information in a column in the gridview
/// </Summary>
/// <Param name = "gridview1"> table object </param>
/// <Param name = "cellnum"> Number of columns to be merged (calculated from 0) </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;
}
}
}
}

/// <Summary>
/// Merge the cells with the same information in the itemtemplate column in The gridview
/// </Summary>
/// <Param name = "gridview1"> table object </param>
/// <Param name = "cellnum"> Number of columns to be merged (calculated from 0) </param>
/// <Param name = "controlname"> name of the hyperlink object in the table </param>
Public static void grouprowsitem (gridview gridview1, int cellnum, string controlname)
{
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 (Hyperlink) gvr. cells [cellnum]. findcontrol (controlname )). TEXT = (Hyperlink) gvrnext. cells [cellnum]. findcontrol (controlname )). 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;
}
}
}
}

Public static void grouprowsitem (gridview gridview1, int cellnum, string controlname, int [] cellnums)
{
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 (Hyperlink) gvr. cells [cellnum]. findcontrol (controlname )). TEXT = (Hyperlink) gvrnext. cells [cellnum]. findcontrol (controlname )). text)
{
Gvrnext. cells [cellnum]. Visible = false;
For (int row = 0; row <cellnums. length; row ++)
{
Gvrnext. cells [cellnums [row]. Visible = false;
}
Rowspannum ++;
}
Else
{
Gvr. cells [cellnum]. rowspan = rowspannum;
For (int row = 0; row <cellnums. length; row ++)
{
Gvr. cells [cellnums [row]. rowspan = rowspannum;
}
Rowspannum = 1;
Break;
}
If (I = gridview1.rows. Count-1)
{
Gvr. cells [cellnum]. rowspan = rowspannum;
For (int row = 0; row <cellnums. length; row ++)
{
Gvr. cells [cellnums [row]. rowspan = rowspannum;
}
}
}
}
}

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.