【问题标题】:ListView ItemDataBound - determine if item is AlternatingItem?ListView ItemDataBound - 确定项目是否为 AlternatingItem?
【发布时间】:2009-10-13 05:58:29
【问题描述】:

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

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

   //Do something   
}

【问题讨论】:

    标签: c# asp.net listview itemdatabound


    【解决方案1】:

    看看这是否有效:

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

    【讨论】:

    • 如果此列表视图使用来自 MSDN 的分页,您应该使用 DisplayIndex 属性而不是 DataItemIndex:“DisplayIndex 表示数据项的位置在当前页面中,而 DataItemIndex 是基于页面偏移的"
    • 谢谢大家,帮了大忙!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多