Lightbulb: How To Access the Item's Index in a DataList or Repeater

Like every other day, I'm blowing through some really complex code trying to create hacks to get around difficult issues. Then, a road block. I have a mind freeze and oops, I forgot what the issue is. I had that earlier today when I forgot how to access the item index number in an ItemTemplate of a DataList or Repeater. I pinged the aspadvice.com lists and Ryan Trudelle-Schwarz responded (although he forgot the big Duh! on the top) to use the Container.ItemIndex. Low and behold, adding this: <%# Container.ItemIndex %> to your code does spit out the Item Index number. After a good hour or so of searching MSDN trying to find it, Ryan came to the rescue. Thanks again Ryan for kick starting my brain.

Published Thursday, January 3, 2008 8:39 PM by Jason N. Gaylord

Comments

No Comments