Reputation: 514
Am trying to add an 'odd' class to a table row in a repeater control..
<tr class="<%# If((Container.ItemIndex % 2 == 0), "even", "odd") %>">
I have verified that Container.ItemIndex returns the index number.
This causes it to throw this error.. First operand in a binary 'If' expression must be nullable or a reference type.
I also tried replacing the % with Mod keyword but it throws an "Expression expected" error..
Am new to coding asp.net in vb, tried searching for a solution but failed to get a working solution..
Upvotes: 2
Views: 1369
Reputation: 3558
you can also try this :
<tr class='<%# ((Container.ItemIndex % 2 == 0) ? "odd": "even") %>' >
Hops its helps
Upvotes: 1
Reputation: 7200
If your target audience have browsers that implement the right CSS3 features, you can also accomplish this task purely with CSS:
http://www.w3.org/Style/Examples/007/evenodd.en.html
Upvotes: 0
Reputation: 112772
Try
<tr class="<%# If((Container.ItemIndex Mod 2 = 0), "even", "odd") %>">
Upvotes: 1