How to dynamically set management identifiers inside a repeater pattern?

Here is an elusive problem that I didn’t find a good answer to on StackOverflow, although there are a couple of hits ... I have a situation where I would like to do this:

<asp:Repeater ID="MyRepeater" runat="server" OnItemDataBound="MyRepeater_ItemDataBound"> <ItemTemplate> <li id="id?"> All the other stuff </li> </ItemTemplate> </asp:Repeater> 

The question is ... how do I get the identifier of my <li> elements id1, id2, id3, etc., based on the ItemIndex to which they are attached? So far, the most ... er ... "elegant" solution that I came up with is to replace the <li> with asp: Literal and reset the <li ...> text. But it just feels ... so wrong. And no, I do not use ASP.NET 4.0, which, as I read, will provide this functionality.

+7
repeater
source share
1 answer

Like this:

 <asp:Repeater ID="MyRepeater" runat="server" OnItemDataBound="MyRepeater_ItemDataBound"> <ItemTemplate> <li id="li<%# ((RepeaterItem)Container).ItemIndex + 1%>"> All the other stuff </li> </ItemTemplate> </asp:Repeater> 
+15
source share

All Articles