最近有做一个关于工厂PA流程的项目,发现显示数据列有很多都是重复的,所有就想了一个办法合并每行内容相同的单元格,贴上代码:
这个function 需要两个参数一个列号和当前的gridview
Protected Sub CellTogether(ByVal cellindex As Integer, ByVal gv As GridView)
Dim i As Integer = 0
Dim rowspannum As Integer = 1
Do While i < gv.Rows.Count - 1
Dim gvr As GridViewRow = gv.Rows(i)
For i = i + 1 To gv.Rows.Count - 1
Dim gvrnext As GridViewRow = gv.Rows(i)
If CType(gvr.Cells(cellindex).Controls(1), Label).Text.ToString.Trim = CType(gvrnext.Cells(cellindex).Controls(1), Label).Text.ToString.Trim Then
rowspannum = rowspannum + 1
gvrnext.Cells(cellindex).Visible = False
Else
gvr.Cells(cellindex).RowSpan = rowspannum
rowspannum = 1
Continue Do
End If
If i = gv.Rows.Count - 1 Then
gvr.Cells(cellindex).RowSpan = rowspannum
Exit Sub
End If
Next
Loop
End Sub
这只是关于列的合并,相同的方法也可以每行中相邻列的合并,各位可以想一下的哇。