Search code examples
asp.netdesign-patternsdata-bindingconditional-statementsmarkup

Conditional Markup in aspx


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?


Solution

  • 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.