Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Anonymous type in Repeater DataBound event

I'm setting the DataSource of an ASP.NET repeater as follows:

rptTargets.DataSource = from t in DB.SalesTargets select new { t.Target, t.SalesRep.RepName };

Now, in the repeater's OnDataBound event, how can I retrieve the RepName and Target properties from the anonymous type contained in e.Item.DataItem?

Many Thanks

like image 515
staterium Avatar asked Jul 31 '09 12:07

staterium


1 Answers

You can use DataBinder.Eval:

string repName = (string)DataBinder.Eval(e.Item.DataItem, "RepName");
string target = (string)DataBinder.Eval(e.Item.DataItem, "Target");
like image 122
Richard Szalay Avatar answered Nov 01 '22 22:11

Richard Szalay