2009-08-25 97 views

回答

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/