话不多说,直接放代码和效果图
/*
''' <summary>
''' 合并单元格
''' </summary>
''' <param name="sender"></param>
''' <param name="e"></param>
*/
Protected Sub dgdData_PreRender(ByVal sender As Object, ByVal e As EventArgs) Handles dgdData.PreRender
Dim sColumns As Integer = 2 /*需要合并的列*/
If dgdData.Items.Count > 1 Then
Dim rowspan As Integer = 0
For i As Integer = 1 To dgdData.Items.Count - 1 /*单元格合并*/
If dgdData.Items(i - 1).Cells(sColumns).Text.Trim() = dgdData.Items(i).Cells(2).Text.Trim() Then /*分页中合并单元格*/
rowspan = rowspan + 1
dgdData.Items(i - rowspan).Cells(sColumns).RowSpan = rowspan + 1
dgdData.Items(i).Cells(sColumns).Visible = False
dgdData.Items(i - rowspan).Cells(sColumns).VerticalAlign = VerticalAlign.Middle
Else
rowspan = 0
End If
Next
End If
End Sub
合并单元格实例
网友评论