这里也是在帮定数据后,再来合并单元格,在GridView1_DataBound里写代码: Protected Sub GridView1_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles GridView1.DataBound For rowIndex As Integer = GridView1.Rows.Count - 2 To 0 Step -1 Dim row As GridViewRow = GridView1.Rows(rowIndex) Dim previousRow As GridViewRow = GridView1.Rows(rowIndex + 1) '合并同运单号的运杂费 If row.Cells(9).Text = previousRow.Cells(9).Text And row.Cells(1).Text = previousRow.Cells(1).Text Then row.Cells(9).RowSpan = IIf(previousRow.Cells(9).RowSpan < 2, 2, previousRow.Cells(9).RowSpan + 1) previousRow.Cells(9).Visible = False End If '合并同运单号的到站 If row.Cells(3).Text = previousRow.Cells(3).Text And row.Cells(1).Text = previousRow.Cells(1).Text Then row.Cells(3).RowSpan = IIf(previousRow.Cells(3).RowSpan < 2, 2, previousRow.Cells(3).RowSpan + 1) previousRow.Cells(3).Visible = False End If '合并同运单号的运输方式 If row.Cells(4).Text = previousRow.Cells(4).Text And row.Cells(1).Text = previousRow.Cells(1).Text Then row.Cells(4).RowSpan = IIf(previousRow.Cells(4).RowSpan < 2, 2, previousRow.Cells(4).RowSpan + 1) previousRow.Cells(4).Visible = False End If '合并同运单号的运杂费 If row.Cells(5).Text = previousRow.Cells(5).Text And row.Cells(1).Text = previousRow.Cells(1).Text Then row.Cells(5).RowSpan = IIf(previousRow.Cells(5).RowSpan < 2, 2, previousRow.Cells(5).RowSpan + 1) previousRow.Cells(5).Visible = False End If Next End Sub