1

我想在第四次迭代中退出 rpt.ItemDataBound 函数,但是当我完成时:

 Protected Sub rptCol_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles rptCol.ItemDataBound
        If Not e.Item.ItemType = ListItemType.AlternatingItem AndAlso Not e.Item.ItemType = ListItemType.Item Then Exit Sub
        If e.Item.ItemIndex = 4 Then
            Exit Sub
        End If

..

它没有用,他只是跳过了这个迭代。

有任何想法吗 ?谢谢

4

4 回答 4

2

就像@Marcus 说的那样,迭代将继续,因为每一行都会调用它。

尝试不同的方法。在绑定到中继器之前更改您的数据源。像这样的东西:

//I am assuming your datasource is a List, but this works for a datatable, etc
List<[YOUR CLASS]> datasource = MethodThatGetsYourSource();
rptCol.DataSource = datasource.Take(4);
rptCol.DataBind();
于 2013-03-01T15:51:57.703 回答
1
Private Sub ForceStopAfterFirstBind(sender As Object, e As RepeaterItemEventArgs)
    If e.Item.ItemIndex > 3 Then
        e.Item.Controls.Clear()
    End If
End Sub

这样称呼它:

ForceStopAfterFirstBind(sender, e)
于 2014-04-17T13:46:11.970 回答
0

我认为您需要尝试 itemCreadedOnDatabound 事件

于 2013-03-01T15:14:14.180 回答
0

迭代将继续,因为将继续为每一行调用事件处理程序。如果想在某行之后跳过逻辑,您可以执行以下操作:

Protected Sub rptCol_ItemDataBound(sender As Object, e As RepeaterItemEventArgs) Handles rptCol.ItemDataBound
    If Not e.Item.ItemType = ListItemType.AlternatingItem AndAlso Not e.Item.ItemType = ListItemType.Item Then Exit Sub
    If e.Item.ItemIndex > 3 Then
        Exit Sub
    End If
 .....
End Sub
于 2013-03-01T15:26:51.697 回答