Reputation: 296
I have my template file which has data being populated into it. However I want to be able to write a class to every odd list element.
The issue i have is that some of the fields being listed are hidden when there is no data and as such i cannot simply write in the class of every other element.
I know I could do this using javascript, but would prefer not to.
Is there any way I can use the page_prerender to look at which list items are going to be displayed and add a class to each odd element?
for example my template looks like this but with many more fields:
<ul>
<li>
<h3>Data title</h3>
<p><%=GetDymanicData1 %></p>
</li>
<!-- if statement to check if data has value, else do not show -->
<li>
<h3>Data title</h3>
<p><%=GetDymanicData2 %></p>
</li>
<li>
<h3>Data title</h3>
<p><%=GetDymanicData2 %></p>
</li>
...
</ul>
Upvotes: 2
Views: 205
Reputation: 9412
Take a look at the Repeater control: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.aspx
The repeater supports supplying a template for each of your data items, as well as an alternating item template, which is applied to every other item in the item list. An example can be found here: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.repeater.alternatingitemtemplate.aspx
Upvotes: 2
Reputation: 60516
This is not c#
this is a question about html
and css
.
You can do this in pure css
. Check out my sample and this jsFiddle Demonstration
CSS
li:first-child {background: #FF0}
li:nth-child(2n+3) {background: #CCC}
Upvotes: 4