Retrieving an item's index

R

Roshawn Dawson

Hi,

I have a Repeater control that contains a textbox in its ItemTemplate.
The textbox will make use of a javascript function. However, this
function needs the index of the textbox in order to work. Here's what I
have:

<asp:Repeater id="Repeater1" runat="server"><ItemTemplate>
<asp:textbox id="TextBox1" text="<%#Container.DataItem("Name")%>"
onblur="javascript:fixName('here is where I get lost')" />
</ItemTemplate></asp:Repeater>

What technique or code can be written to populate this at runtime?

Thx,
Roshawn
 
B

Brock Allen

You can use the DataBinding syntax (<%# %>) and then fetch whatever info
you need from the Container object (which is just a reference to the RepeaterItem
and it has an ItemIndex property:

<asp:Repeater id="Repeater1" runat="server"><ItemTemplate>
<asp:textbox id="TextBox1" text="<%#Container.DataItem("Name")%>"
onblur='javascript:fixName(<%# Container.ItemIndex %>)' />
</ItemTemplate></asp:Repeater>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top