View Single Post
  #2 (permalink)  
Old June 13th, 2009, 03:12 PM
philip_cole philip_cole is offline
Friend of Wrox
Points: 894, Level: 11
Points: 894, Level: 11 Points: 894, Level: 11 Points: 894, Level: 11
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2005
Location: London, , United Kingdom.
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
Default Cast to ListViewDataItem

Hi David,

In the ItemDataBound event for items which are ListViewItemType.DataItem, e.Item is of type ListViewDataItem. You can cast e.Item to this and then use its DataItem property the same as with the GridView. The example on msdn at http://msdn.microsoft.com/en-us/libr...wdataitem.aspx is similar.

So your code could be:
Code:
protected void listProducts_ItemDataBound(object sender, ListViewItemEventArgs e)
{
  if (e.Item.ItemType == ListViewItemType.DataItem)
  {
    ListViewDataItem dataItem = (ListViewDataItem)e.Item;
    string prodtype = (string)DataBinder.Eval(dataItem, "ProductType");
    // ...
  }
}
HTH
Phil