C# ItemDataBound中中继器的退出Sub

C# ItemDataBound中中继器的退出Sub,c#,asp.net,.net,vb.net,C#,Asp.net,.net,Vb.net,我希望在第4次迭代时退出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 = ListItem

我希望在第4次迭代时退出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

它不起作用,他只是跳过了这个迭代

有什么想法吗?
谢谢

我认为您需要尝试ItemCreadendOnDatabound事件

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

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

就像@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();
//我假设您的数据源是一个列表,但这适用于datatable等
List datasource=MethodThatGetsYourSource();
rptCol.DataSource=DataSource.Take(4);
rptCol.DataBind();
可以这样说:

ForceStopAfterFirstBind(sender, e)

为任何额外逻辑生成项后,将调用
ItemDataBound
方法。跳过该事件无效。你是想把那些行完全排除在外吗?是的,没错。我还尝试了return而不是exist sub,但它不起作用尝试“If e.Item.ItemIndex>=4 Then”,但这只会阻止这些项的数据绑定(而不是模板化和itemcreated处理)@user1187282您正在尝试在Repeater控件中实现分页吗?我只是好奇。我试过了,但没用。我就是这么做的。受保护的子rptCol_ItemCreated(发送方作为对象,e作为RepeaterItemEventArgs)处理rptCol.ItemCreated如果e.Item.ItemIndex=3,则退出Sub End如果End Sub我想退出函数而不仅仅跳过该项,是否可能
ForceStopAfterFirstBind(sender, e)