代码之家  ›  专栏  ›  技术社区  ›  mccrager

如何从绑定到ASP.NET转发器的数据项中删除当前数据项?

  •  2
  • mccrager  · 技术社区  · 15 年前

    我想评估当前绑定到中继器的数据项,并在我的条件满足时将其从添加中删除。我本以为将e.item.dataitem设置为Nothing会起作用,但它不起作用。当某个条件满足时,如何不向中继器添加数据项有什么想法吗?

    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
    
    2 回复  |  直到 12 年前
        1
  •  2
  •   Shawn Steward    15 年前

    您是否尝试将项目的可见性设置为false?

    If true Then
      //don't add the current item
      e.Item.Visible = False
    Else
      //add the current item
    End If
    
        2
  •  1
  •   David Hedlund    15 年前

    你走错了方向。此时在代码中,已经添加了一个项,您只是在绑定(填充)它。您要做的是在将结果集设置为 DataSource ,在您呼叫之前 repeater.DataBind