You can only define a GroupItemCount in the ListView, but what if you want to do grouping based on a property of the items in the data source? Sort of an ad-hoc group by. Th
When I had to add basic group headings in a repeater I did so with a Literal control in the ItemTemplate:
<asp:Literal runat="server" Text='<%# GetGroupHeading(Eval("Group")) %>' />
The 'GetGroupHeading' method in the code kept track of the previous group heading and sent back '<h2>Group Name</h2>', or an empty string if we were on the same group as the previous item. As I said though, I did this on a Repeater, so not sure if it will cover what you need for a ListView.
Yes Nick gave a great lead. Here's my code-behind
Dim sCategory_Descr As String
Function GetGroupHeading(ByVal sGroupName As String) As String
Dim sReturn As String
If sCategory_Descr <> sGroupName Then
sCategory_Descr = sGroupName
sReturn = "<H5>Category: " & UCase(sGroupName) & "</H5>"
Else
sReturn = ""
End If
Return sReturn
End Function
And my item_template
<ItemTemplate>
<tr>
<td style="background-color:#ccc;" colspan="2" id="tdCategory_Placeholder" runat="server" >
<asp:Label Font-Bold="true" ID="Literal1" runat="server" Text='<%# GetGroupHeading(Eval("Category_Descr")) %>' />
</td>
</tr>
<tr>
<td >
<asp:DynamicControl1 />
</td>
<td >
<asp:DynamicControl2 />
</td>
</tr>
</ItemTemplate>
Try this article from 4 Guys from Rolla: Using ASP.NET 3.5's ListView and DataPager Controls: Grouping Data with the ListView Control