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

标签 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   
}

最佳答案

看看这是否有效:

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

关于c# - ListView ItemDataBound - 确定项目是否为 AlternatingItem?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1558410/

相关文章:

c# - 如何使用不是第二个对象的主键的键创建导航属性?

c# - 转换为 Base64 时从字节数组中获取反转图像

c# - 如何通过 HTML5 报告查看器使用 Telerik Reports

ASP.NET:如何正确重定向出现 404 错误的请求?

c# - 记住单个页面上的状态时,使用隐藏字段总是比 session 更好吗?

c# - 如何使用 Compact Framework 获取 ListView 中最可见的项目?

c# - 在 MonoTouch 中获取多个 TextField 的值

asp.net - MVC HtmlHelpers : can you write into the page header?

android - RecyclerView 中特定 TextView 的滚动条不起作用

listview - 如何通过 ListView 进行过滤