if/then logic in a repeater control. best methods?

  • Thread starter Thread starter Darrel
  • Start date Start date
D

Darrel

I go back and forth between repeater controls and just using good ol' string
builders to build formatted output from a db query.

I'm working on a project where I'd really like to keep all the formatting
markup on the front-end for the non-.net folks to be able to updates.
Obvioudly, a repeater control makes a lot of sense for this.

The challenge is that this is an events list, so my data may be:

10/2/07 event
10/7/07 event
11/22/07 event
12/14/07 event

The above in a repeater is easy enough, but I need to insert a month before
each item that starts in a new month. So, it needs to look like this:

October 2007
2 event
7 event

November 2007
22 event

December 2007
14 event

Any best practices for accomplishing that via a repeater control and/or
another way to keep the front-end markup on the front end (ie, not
compiled)?

I could move my if/then logic to the front end and use response.write for it
all, but that doesn't seem a very 'modern' solution.

-Darrel
 
The way of doing this sort of things is to make an itemtemplate out of 2
rows, one for month and another for event. Then in the ItemDataBound, or
even better in the PreRender event, you can see if the event date passed
through a month boundary, you will set the month value and make the month
row visible. If the event is in the same month with the previous one, you
will make the month row hidden.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net
 
Back
Top