I’ve been thrown a problem regarding ASP and C# without any experience in either and on a server that I have limited access to and where I can’t see proper error logs. So prepare yourselves for a potentially confusing question 🙂
We have a loop (an ASP repeater) in a HTML template and a part of the HTML in the template should only be included in the first iteration of the loop. Unfortunately I can’t just hide the html for the other iterations, I need to remove it.
So essentially want to do this:
<% if (Container.ItemIndex == 0) { %>
Lots of HTML here
<% } %>
Problem is this produces an error (and I can’t see the logs so I don’t know exactly why…). I know the if statement itself works (setting 0 == 0 instead works as an example), and I can get the index normally, just not here.
So the question is, how does one do something like this? Can I access the index in the C# if statement or is there something built into the repeater that I can use?
Rather than using an If statement, I would nest the “0 index only” content inside an ASP.NET
Placeholderweb control, and setvisible=trueonly for the first item.As @Amiram has stated, you could do:
Alternatively, set
visible="false"and change this value in theItemDataBoundevent: