Selectively displayed HTML in ItemTemplate of repeater control

M

msielski

I apologize if I don't explain this clearly, or if the solution is an
obvious one. I have been using ASP classic for a few years, but only
recently started with ASP.net. I have been reading Stephen Walther's
ASP.NET Unleashed 2nd Ed with much success, but have not been able to
figure out this issue:

I have a repeater web control on my page. I want to have a block of
HTML code appear within certain rows based on the value of a field in
the corresponding row of data. A simple example would be a repeater
listing products that displays 'New' icons next to the new ones.

In old ASP I would have probably put an IF block right there with the
optional HTML inside it. This isn't allowed in ASP.net, and rightly so
I suppose since it mixes code and presentation.

I have been very impressed with ASP.net so far and I'm sure there's a
reasonable way to do this. I have been searching and reading with no
luck. Any suggestions?

Thanks,
Matt
 
M

msielski

Sometimes spelling out the problem helps make more clear how to search
for its answer. Just after I posted, I found a solution in:

http://groups-beta.google.com/group...d1db4592d?q=repeater&rnum=37#095f0fdd1db4592d

Seems like this will work. Please let me know if this is not the best
way to do it. What concerns me is that it requires putting HTML in a
function in the code-behind file, which would seem to mix up code and
presentation. However, it's still cleaner than the

<% if ... %> html <% end if %>

I would have done previously.

-Matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top