代码之家  ›  专栏  ›  技术社区  ›  kevindaub

在ASP。Net ListView

  •  1
  • kevindaub  · 技术社区  · 16 年前

    我是ASP新手。网。我正试图使用列表视图显示我的sql结果。我使用该示例按数据字段对结果进行分组 4GuysFromRolla.com website

    谢谢。

    2 回复  |  直到 16 年前
        2
  •  0
  •   Martin    16 年前

    我从未使用过ListView,但我确实在GridView中进行了分组。如果需要,可以尝试将其移植到ListView:

    Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
        Dim tblGrid As Table = Me.GridView1.Controls(0)
        Dim strLastCat As String = "@"
        Dim row As GridViewRow
    
    
        For Each row In GridView1.Rows
            Dim intRealIndex As Integer = tblGrid.Rows.GetRowIndex(row)
            Dim strCat As String = Me.GridView1.DataKeys(row.RowIndex).Value
    
            If strLastCat <> strCat Then
                Dim rowHeader As New GridViewRow(intRealIndex, intRealIndex, DataControlRowType.Separator, DataControlRowState.Normal)
                Dim newCell As New TableCell
    
                newCell.ColumnSpan = Me.GridView1.Columns.Count
                newCell.BackColor = System.Drawing.Color.FromArgb(61, 138, 20)
                newCell.ForeColor = System.Drawing.Color.FromArgb(255, 255, 255)
                newCell.Font.Bold = True
                newCell.Font.Size = New FontUnit(FontSize.Larger)
                newCell.Text = strCat
    
                rowHeader.Cells.Add(newCell)
                tblGrid.Controls.AddAt(intRealIndex, rowHeader)
                strLastCat = strCat
    
            End If
    
        Next
    
        MyBase.Render(writer)
    End Sub
    

    http://www.truedietreviews.com/diet-reviews/