【发布时间】:2012-06-02 16:20:21
【问题描述】:
我试图在处理OnItemDataBound 事件时获取转发器中的项目数。我要实现的目标非常简单;我正在尝试在中继器内的最后一项上隐藏某个标签。目前我正在连接ItemIndex 和Items.Count,但是在OnItemDataBound 期间,索引和计数一起增加。
这是我目前所得到的:
Label myLabel = e.Item.FindControl<Label>("MyLabel");
if (myLabel != null)
{
// as the item index is zero, I'll need to check against the collection minus 1?
bool isLastItem = e.item.ItemIndex < (((Repeater)sender).Items.Count - 1);
myLabel.Visible = !isLastItem;
}
我知道我可以将 DataSource 强制转换为绑定的数据项的集合,但是 OnItemDataBound 事件处理程序正在跨多个转发器使用,所以我需要一些更通用的东西。
【问题讨论】:
标签: c# asp.net .net collections web-controls