Warning: this is a nerdy code post, so proceed with caution

While modding my new site in
Community Server 2007, I needed to know the item number in the asp:Repeater control so when I reach the last one (the repeater had a fixed number of items) it would not apply a certain CSS class so there isn't a redundant border. I didn't want to inherit the Repeater control and implement the logic in the Render event because I wanted to do it declaratively (because I was lazy basically). It was not immediately obvious as to how, and I still don't know why it is the case, but it works.
First, in the aspx page where the asp:Repeater control lies, add in the following somewhere:
<script language="C#" runat="Server">
//needed as cannot get Container.ItemIndex directly
int GetItemIndex(int index)
{
return index;
}
</script>
Then inside the ItemTemplate tags of your asp:Repeater control, access the item number (ItemIndex) using the following code:
GetItemIndex(Container.ItemIndex);
You'll have to combine it with something else though because that code above does nothing with the number. Something like this to print it:
<%# GetItemIndex(Container.ItemIndex) %>
Or, this to use it conditionally:
<%# GetItemIndex(Container.ItemIndex) % 2 == 0 ? "print-this-if-true" : "print-this-if-false" %>
There's a ton of things you can do with this code, like create a new table row every 3 items, or make every 5th item red.
Why you can only access Container.ItemIndex when it's wrapped around a method I have no idea, but it didn't work until I did that. There are obviously some intricacies of ASP.NET that my hacking isn't picking up - I've never done ASP.NET coding before, just winforms stuff.
Hope this helps someone hacking through ASP.NET!