Why is e.Item.DataItem null on ItemDataBound event when binding an asp:net Repeater to a Collection?

Posted by Clean on Stack Overflow See other posts from Stack Overflow or by Clean
Published on 2010-04-12T10:12:44Z Indexed on 2010/04/12 10:33 UTC
Read the original article Hit count: 314

Filed under:
|
|

Hi,

I'm trying to bind a collection implementing the ICollection, IEnumerable and IList interface to an asp.net repeater. The Collection is named CustomCollection. So I'm setting the datasource of the repeater to the collection, as follows:

rptRepeater.DataSource = customCollection;
rptRepeater.Databind();

Then, on the ItemDataBound event, I'm trying to access the DataItem object, as follow:

void rptRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e){

object obj = e.Item.DataItem; // DataItem is null for some reason

}

For some reason the e.Item.DataItem object is null. Do anyone know why this is, and/or what I could do to get hold of the object in the collection that is to be databound to the repeater?

Thanx!

© Stack Overflow or respective owner

Related posts about ASP.NET

Related posts about c#