1

I am new to ASP.NET. I am trying to display my sql results using a list view. I am using the example for grouping my results by a data field from the 4GuysFromRolla.com website. However, I find the way of grouping the items by a data field to be a bit clumsy. Is there a better way to do it?

Thanks.

2 Answers 2

2

Nested ListView - http://mattberseth.com/blog/2008/01/building_a_grouping_grid_with.html

Sign up to request clarification or add additional context in comments.

2 Comments

I was unsure with using Linq to SQL, but once I added the relationships to the dbml, It worked like a charm. Thanks.
Site is offline, but the Wayback Machine pulls through again. web.archive.org/web/20101125093922/http://mattberseth.com/blog/…
0

I have never used a ListView, but I did do grouping in a GridView. You can try porting this over to a ListView if you want:

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

The code creates headers each category. The final version can be viewed here: http://www.truedietreviews.com/diet-reviews/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.