multiple controls with same ID

D

Daves

say I have a Datalist and each row has a image control with ID "MyImg". I am
hiding/showing each image based on a result from the database. I need to
find that particular img control to access it's properties. Obviously it
isn't possible to just say FindControl("MyImg") since there are multiple
instances of it. I once found an article on this subject but cannot find it
now, anyone?
 
K

Karl Seguin

Daves:
Your statement isn't fully accurate. You can use FindControl("MyImg")
within the image's parent control and all will work as expected. For
example ,if you are in the ItemDataBound event, you could do
e.Item.FindControl("MyImg") e is the argument which is received.

If you aren't in the ItemDataBoundEvent you can simply loop thorugh all the
items of the datalist'

for each item as DataListItem in myList.Items
'item.FindControl
next


Karl
 

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

Forum statistics

Threads
473,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top