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

发布于 2024-08-07 11:37:06 字数 370 浏览 3 评论 0原文

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

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

   //Do something   
}

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   
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

因为看清所以看轻 2024-08-14 11:37:06

看看这是否有效:

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

see if this works:

int currentIndex = currentItem.DisplayIndex;
if (currentIndex % 2 == 1)
{
    // alternating item
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文