ListView ItemDataBound - 确定项目是否为AlternatingItem?

时间:2009-10-13 05:58:29

标签: c# asp.net listview itemdatabound

我正在使用Listview来显示我的数据。在ItemDatabound事件中,我想做一些操作并更改显示的一些数据。当我在这个事件上检查项目时,我使用下面的代码,但我需要知道该项目是否是一个交替项目,因为这将影响我想要对该行做什么。有人能指出我正确的方向吗?

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

   //Do something   
}

1 个答案:

答案 0 :(得分:4)

看看是否有效:

int currentIndex = currentItem.DisplayIndex;
if (currentIndex % 2 == 1)
{
    // alternating item
}