我想评估绑定到转发器的当前DataItem,并在条件满足时将其删除。我原以为将e.Item.DataItem设置为Nothing会起作用,但事实并非如此。任何想法如何在特定条件满足时如何不向转发器添加DataItem?
Protected Sub rpt_OnItemDataBound(ByVal sender As Object, ByVal e As RepeaterItemEventArgs)
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
If true Then
'don't add the current item
e.Item.DataItem = Nothing
Else
'add the current item
End If
End If
End Sub
答案 0 :(得分:2)
您是否尝试将项目的可见性设置为False?
If true Then
//don't add the current item
e.Item.Visible = False
Else
//add the current item
End If
答案 1 :(得分:1)
你的方式错了。在代码的这一点上,已经添加了一个项目,并且您只是绑定(填充)它。您要执行的操作是在将结果集设置为DataSource
之前过滤结果集,然后再致电repeater.DataBind