tags:

views:

64

answers:

1

I have a repeater. I can access individual properties of the element being repeated on - e.g. if my repeater is bound to a list of people, I can access 'FirstName' with

 #Eval("FirstName").

However, I would like to actually store the current element in a variable

Person person = ... GetCurrentElement ...

Is there any way to do this?

A: 

If your repeater is data bound to a collection of Persons, then the DataItem object contains the actual Person object of each element in the repeater, but only in events where that concept makes sense.

For example, you can access the underlying Person in the ItemDataBound event:

Protected Sub rptPeople_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptPeople.ItemDataBound
    Dim person as Person = CType(e.Item.DataItem, Person)
End Sub
Jason Berkan