Dynamic CSS via DataItemIndex

3 posts, 1 answers
  1. Angie
    Angie avatar
    101 posts
    Member since:
    Jan 2008

    Posted 23 Aug 2012 Link to this post

    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. Answer
    Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 24 Aug 2012 Link to this post

    Hello,

    You can set the Css Class as follows.

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

    Hope this helps.

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Angie
    Angie avatar
    101 posts
    Member since:
    Jan 2008

    Posted 27 Aug 2012 Link to this post

    Thanks Princy!  :-)
Back to Top