Selectively displayed HTML in ItemTemplate of repeater control
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?
Re: Selectively displayed HTML in ItemTemplate of repeater control
Sometimes spelling out the problem helps make more clear how to search
for its answer. Just after I posted, I found a solution in:
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.
|All times are GMT. The time now is 10:53 AM.|
Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.