Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Grouping Data with a Repeater Control

2 views
Skip to first unread message

Jason

unread,
Jan 14, 2003, 9:10:22 PM1/14/03
to

I have succesfully implemented the Repeater control but I
am unable to create any kind of group headers. Basically
the dataset consists of information regarding a fault
that a client has logged. Each fault has a category and
the dataset is ordered by this field. What I would like
to do is display the category each time it changes.

Any help that can be provided will be much appreciated.

Regards,

Jason.

Erik Porter [.NET MVP]

unread,
Jan 15, 2003, 12:12:46 AM1/15/03
to

There's not really any automatic way to do that, you're going to have to
write some code to do it.

One way might be to keep a public variable of the last category in the
ItemDataBound Event and check to see if it's changed and print it out into a
Literal or Label and if it hasn't, don't print out anything.

The ItemDataBound Event gets fired off once for every row that was
DataBound.

-Erik Porter
Microsoft .NET MVP

"Jason" <jgta...@mccaffertys.com.au> wrote in message
news:61dd01c2bc3b$42ab2540$cef82ecf@TK2MSFTNGXA08...

Jason Taylor

unread,
Jan 15, 2003, 1:15:35 AM1/15/03
to
Eric,

Thankyou very much for your reply. Based on what you suggested I was
able to come up with the following solution. I hope this will be of some
use to other developers. :)

Okay in the page code I created the following variable outside of the
procedures:
Dim strCategory as String

I used this to track the last category displayed.

Then I set my ItemTemplate as follows:
<ItemTemplate>
<%# RetrieveCategory(Container.DataItem("Category")) %>
<tr>
<td><%# Container.DataItem("Field1") %></td>
<td><%# Container.DataItem("Field2") %></td>
</tr>
</ItemTemplate>

Then the RetrieveCategory Function:
Public Function RetrieveCategory(ByVal pstrCategory As _ String) As
String
If Not (strCategory = pstrCategory) Then
strCategory = pstrCategory
RetrieveCategory = "<tr><td colspan = 2>" & _
strCategory & _
"</td></tr>"
Else
RetrieveCategory = vbNullString
End If
End Function

I hope this is clear. One other consideration I should address is that I
used the function to output the table tags. If the category has changed
it puts the table row in, and if it hasen't it doesn't insert anything
thus keeping my table nice & neat. :)

Thanks for your help Eric. :)

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

0 new messages