Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to cast object from (object sender, ListViewItemEventArgs e)

I am using the ListView Control with the following datasource List<MyObject>

On my listview control i have an OnItemDataBound

My question is how do get the current value of MyObject. Ie myObj[5].FirstName

protected void ItemsListViewDataBound(object sender, ListViewItemEventArgs e) { // I want to do some kind of a cast here

}

like image 276
frosty Avatar asked Dec 23 '08 09:12

frosty


1 Answers

protected void MyListView_DataBind(object sender, ListViewItemEventArgs e){
  if(e.Item.ItemType == ListViewItemType.DataItem){
    MyObject p = (MyObject)((ListViewDataItem)e.Item).DataItem;
  }
}

You'll want to do the type check so that you don't try and do a cast when you're working on say, the header item.

like image 92
Aaron Powell Avatar answered Nov 15 '22 07:11

Aaron Powell