The solution is as follows (written in a public module, defined as a static method for easy invocation):
Copy Code code as follows:
<summary>
Merge rows (cells) with the same information from a column in the GridView
</summary>
<param name= "GridView1" >GridView</param>
<param name= "Cellnum" > The first few columns </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 multiple columns require consolidation, appropriate modifications can be made.
A complete life should be forgiveness, tolerance, waiting and love!