views:

104

answers:

2

Hi...

I have a ListView. If I want to base the html markup on a condition in respects to the databound item, what would be the best way to do that?

What I mean is, is there any other way then putting <% %> if/else blocks directly in the markup?

I'm aware that a really ugly way of doing it, is putting html markup in the database field, and just let the Eval() squeeze out the proper markup (I'm not doing that).

I would like to avoid putting actual <% %> C# blocks in the code as well.

Any good ideas?

EDIT: I'm thinking about making 3 different asp:panels set visible:false, and then in the databound event of the listview, set the appropriate panel visible:true based on the condition - anyone have any design-opinions about this idea?

A: 

Solved...

Ended up with the 3 panels, and then checking the condition in the itemDataBound event...

I'd still like opinion on the design implications of this solution though.

Dynde
A: 

Overriding one of the 'render' event of one of the listview 'cells' should do the trick. Writing you own code for conditional markup isn't that bad considering the alternatives.

But please do use as much as possible CSS for the real makeup of the page.

Barfieldmv