1

我是 ASP.NET 的新手。我正在尝试使用列表视图显示我的 sql 结果。我正在使用该示例按来自4GuysFromRolla.com 网站的数据字段对我的结果进行分组。但是,我发现按数据字段对项目进行分组的方式有点笨拙。有更好的方法吗?

谢谢。

4

2 回答 2

2

嵌套列表视图 - http://mattberseth.com/blog/2008/01/building_a_grouping_grid_with.html

于 2009-08-25T01:16:11.477 回答
0

我从未使用过 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/

于 2009-08-25T02:37:55.063 回答