将行单元组合用于中继器记录

时间:2017-03-29 02:07:22

标签: asp.net vb.net

我想在重复广告系列代码和车辆号码时尝试组合行单元格,如下图所示。下面列出的结果是gridview 20页面大小

问题

  1. 例如,当网格视图页面大小设置为2时,行单元格不再组合。结果显示每个分开的记录。
  2. 如果广告系列代码按升序/降序排序,则即使广告系列代码与车辆号匹配,最后一个记录行单元格也始终不会合并。下图显示的广告系列代码按升序排序。因此,当活动代码按降序排序时,所有CMP002都会合并,而CMP001的最后一条记录将不再组合,如下图所示。
  3. 代码背后

     Private Sub GV_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles GV.RowDataBound
    
        For rowIndex As Integer = GV.Rows.Count - 2 To 0 Step -1
    
            Dim gvRow As GridViewRow = GV.Rows(rowIndex)
            Dim gvPreviousRow As GridViewRow = GV.Rows(rowIndex + 1)
            Dim sCurrCampaignCode As String = GV.DataKeys(rowIndex).Values("CAMPAIGN_CODE")
            Dim sCurrVehicleNo As String = GV.DataKeys(rowIndex).Values("VEHICLE_NO")
            Dim sPreviousCampaignCode As String = GV.DataKeys(rowIndex + 1).Values("CAMPAIG_CODE")
            Dim sPreviousVehicleNo As String = GV.DataKeys(rowIndex + 1).Values("VEHICLE_NO")
    
    
            If sCurrCampaignCode = sPreviousCampaignCode AndAlso sCurrVehicleNo = sPreviousVehicleNo Then
    
                If sCurrCampaignCode = sPreviousCampaignCode Then
    
                        If gvPreviousRow.Cells(1).RowSpan < 2 Then
                            gvRow.Cells(1).RowSpan = 2
                            gvRow.Cells(2).RowSpan = 2
                            gvRow.Cells(3).RowSpan = 2
                        Else
                            gvRow.Cells(1).RowSpan = gvPreviousRow.Cells(1).RowSpan + 1
                            gvRow.Cells(2).RowSpan = gvPreviousRow.Cells(2).RowSpan + 1
                            gvRow.Cells(3).RowSpan = gvPreviousRow.Cells(3).RowSpan + 1
                        End If
    
                        gvPreviousRow.Cells(1).Visible = False
                        gvPreviousRow.Cells(2).Visible = False
                        gvPreviousRow.Cells(3).Visible = False
                End If
    
            End If
    
        Next
    
    End Sub
    

    enter image description here

1 个答案:

答案 0 :(得分:0)

我刚刚找到了解决方案。代码必须从RowDataBound移动到OnDataBound而不是