2

I'm using the Listview to display my data. On the ItemDatabound event I want to do some manipulation and change some of the data being displayed. When I check the Item on this event I am using the following code, But I need to know if the item is an alternating item as this will effect what I want to do with the row. Can anyone point me in the right direction?

if (e.Item.ItemType == ListViewItemType.DataItem)
{
   ListViewDataItem currentItem = (ListViewDataItem)e.Item;
   DataKey currentDataKey = myLilstView.DataKeys[currentItem.DataItemIndex];

   //Do something   
}
macou
  • 777
  • 8
  • 21

1 Answers1

4

see if this works:

int currentIndex = currentItem.DisplayIndex;
if (currentIndex % 2 == 1)
{
    // alternating item
}
Omer Bokhari
  • 57,458
  • 12
  • 44
  • 58
  • 1
    You should use the *DisplayIndex* property instead of *DataItemIndex* if this list view is using paging from MSDN: "DisplayIndex represents the position of the data item in the current page, whereas DataItemIndex is based on the page offset" – dariom Oct 13 '09 at 07:02