Repeater

G

Gav

If I'm using a repeater do display... oh lets say images... is it possible
to get a unique ID for each image?

<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<img Id="Image" src="<%# DataBinder.Eval(Container.DataItem,
"ImgSrc") %>">
</ItemTemplate>
</asp:Repeater>

Having it like this every image has the same id of 'Image' how can I get it
to be Image1, Image2 etc if possible.

Thanks
Gav
 
L

Lintie

Create a public variable, e.g. ImgCounter. Set it to a starting value. In
the repeater, change the image line to:
<img id="Image<%=ImgCounter++%>" src="......
 
J

Jeffrey Tan[MSFT]

Hi Gav,

Based on my understanding, you want to specify a unique id for your image
in each row in Repeater control.

Because your <img> is a client side html tag, you can follow Lintie's
suggestion of using legacy asp syntax.

What I want to inform you is that, for Asp.net server side control, you can
only do databinding for the property, like this:
<asp: tagname property="<%#%>" ....>
But, for the ID property, you can not do databinding. So <asp: tagname
ID="<%#%>" ....> will generate parse error on web form.

Also, for Asp.net Web controls(Especially for Repeater controls) on Web
Form, we use the naming space for the ID. It is similiar as the NameSpace
for the control ID(To keep the ID unique on the web form). So multi-rows in
the Repeater control may have the same ID.

For more information, please refer to:
"Web Forms Control Identification"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbconwebformscontrolidentification.asp
"Referencing Controls in Web Forms Pages"
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/
vbtskreferencingcontrolsinwebformspages.asp

Anyway, for your issue, Lintie's suggestion should work for you.

Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
G

Gav

thanks for the advise but it doesn't help in my case... I want to uniquely
identify each client side html tag so that they can be accessed using
javascript. Also I cannot use the 'this' clause because i will need to
access several controls in the row in one call.
 
J

Jeffrey Tan[MSFT]

Hi Gav,

Thanks for your feedback.

To specify a unique identity for your html tag in repeater control, I think
Lintie's suggestion should meet your need.

Also, in the javascript, "this" represents that html tag, if you want to
get the entire row of the table(<tr> tag), you may use this.parent.parent.
(this.parent is <td> tag)

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
J

Jeffrey Tan[MSFT]

Hi Gav,

Does the my reply make sense to you? Is your problem resolved?

Please feel free to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 

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

Top