This is a migrated thread and some comments may be shown as answers.

Dynamic CSS via DataItemIndex

2 Answers 40 Views
ListView
This is a migrated thread and some comments may be shown as answers.
Angie
Top achievements
Rank 1
Angie asked on 23 Aug 2012, 11:34 PM
Hello.  Is it possible to access the DataItemIndex of the ListView on the aspx side in order to dynamically assign a CSS Class?
IE, something like:

<%# DataBinder.Eval(Container.DataItem.ItemIndex) % 2 == 0 ? "itemText" : "itemTextAlt" %>

What would be the proper syntax?  Thanks!

2 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 1
answered on 24 Aug 2012, 06:35 AM
Hello,

You can set the Css Class as follows.

ASPX:
CssClass='<%# Container.DataItemIndex % 2 == 0 ? "itemText" : "itemTextAlt" %>'

Hope this helps.

Thanks,
Princy.
0
Angie
Top achievements
Rank 1
answered on 27 Aug 2012, 03:33 PM
Thanks Princy!  :-)
Tags
ListView
Asked by
Angie
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Angie
Top achievements
Rank 1
Share this question
or