ItemDataBound question

L

Loading name...

hey

asp.net 2.0

I have a ItemDataBound event in my repeater control. My problem is that I
don't know how to access the data in the ItemDataBound control. Lets say the
datasource has a field named "helloworld" and I have a label named "lblName"
in the repeater control:

lbName = e.item["helloworld"]
(but e.item["helloworld"] isn't correct, I get a compile error)

any suggestions on how to reference the data in a ItemDataBound event
 
E

Eliyahu Goldin

To access a label in the item template use

e.Item.FindControl["lblName"]

To access a field in the datasource use

(e.Item.DataItem as <whatever your datasource type is>)["helloworld"]

Are you sure you can't just databind the label to the field?
 

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,772
Messages
2,569,593
Members
45,111
Latest member
KetoBurn
Top