ItemDataBound question

  • Thread starter Thread starter Loading name...
  • Start date Start date
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
 
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?
 
Back
Top