Repeater and Index Value

  • Thread starter Thread starter Stan SR
  • Start date Start date
S

Stan SR

Hi,

I use a repeater that displays images.
I need to add dynamically a jscript function on each image that use the
index value of the repeater

<asp:Repeater ID="ph" runat="server" DataSourceID="myDataSource">
<ItemTemplate>
<asp:HyperLink runat="server" ID="link"
NavigateUrl="javascript:Slides(INDEXREPEATER)">
<asp:Image runat="server" ID="img" ImageUrl='<%#
Eval("myPic") %>' />
</ItemTemplate>
</asp:Repeater>

How to replace the INDEXREPEATER by the current index ?

Thanks in advance

Stan
 
Stan said:
Hi,

I use a repeater that displays images.
I need to add dynamically a jscript function on each image that use
the index value of the repeater

<asp:Repeater ID="ph" runat="server" DataSourceID="myDataSource">
<ItemTemplate>
<asp:HyperLink runat="server" ID="link"
NavigateUrl="javascript:Slides(INDEXREPEATER)">
<asp:Image runat="server" ID="img" ImageUrl='<%#
Eval("myPic") %>' />
</ItemTemplate>
</asp:Repeater>

How to replace the INDEXREPEATER by the current index ?

<%# DataBinder.ItemIndex %>
 
Stan said:
Hi,

I use a repeater that displays images.
I need to add dynamically a jscript function on each image that use
the index value of the repeater

<asp:Repeater ID="ph" runat="server" DataSourceID="myDataSource">
<ItemTemplate>
<asp:HyperLink runat="server" ID="link"
NavigateUrl="javascript:Slides(INDEXREPEATER)">
<asp:Image runat="server" ID="img" ImageUrl='<%#
Eval("myPic") %>' />
</ItemTemplate>
</asp:Repeater>

How to replace the INDEXREPEATER by the current index ?

<%#Container.ItemIndex %>
 
Great.. it works..
I thank you
but now, I have a little problem :(
When I use
<asp:HyperLink id="link" runat="server"
NavigateUrl='javascript:Slides(<%=Container.ItemIndex%>);' >bla
bla</asp:Hyperlink> it doesn't eval the Container.ItemIndex

So when I look at my source, I get
<a href="javascript:Slides(<%=Container.ItemIndex%>);">bla bla</a>


Any idea ??

Stan
 
Stan said:
Great.. it works..
I thank you
but now, I have a little problem :(
When I use
<asp:HyperLink id="link" runat="server"
NavigateUrl='javascript:Slides(<%=Container.ItemIndex%>);' >bla
bla</asp:Hyperlink> it doesn't eval the Container.ItemIndex

So when I look at my source, I get
<a href="javascript:Slides(<%=Container.ItemIndex%>);">bla bla</a>


Any idea ??

Stan

Try:

<asp:HyperLink id="link" runat="server"
NavigateUrl='<%# "javascript:Slides(" + Container.ItemIndex + ");" %>' >bla
bla</asp:Hyperlink>
 
Back
Top