E.Row.DataItem is a list

I use this bit of code in the code behind a OnRowDataBound comand of a gridview:


(int)DataBinder.Eval(e.Row.DataItem, "SectorID")

I have made some changes to my Class so that SectorID is now a list of ints. How do i return the first item in the list using the above method?

cheers

monkey

Cheers, that’s worked. I thinks my brain my have been slightly fried by Friday and a fresh look on monday has sorted it out!

Cheers all for your input :slight_smile:

monkey

e.Row.DataItem will probably be an object, so it will first need to be casted to the appropriate type.

Cheers,
D.

Hi

What is SectorID? Is that a property on and object or what?

e is the current item, if you want the 1st item in the list, you must load it into a public variable before the repeater gets boud

I can’t get this to work:


DataBinder.Eval(e.Row.DataItemIndex, "SectorID");

I get various errors to do with casting and have tried various things. I want the first item in the list which is an int - how do i say which list item i want? Am i correct in saying that the cod above returns the list as an object? If so how do i then extract what i want - can this be done on one line?

cheers for your help

monkey

using e.Item.ItemIndex
(check case with VS, i am not sure of the case).

Not sure if this will work…

DataBinder.GetIndexedPropertyValue(e.Row.DataItem, “SectorID[0]”);