2013-03-01 63 views
1

中繼退出小組我想在4第四次迭代退出rpt.ItemDataBound功能,但是當我做了:在的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 

..

它沒有工作,他只是跳過這個迭代。

有什麼想法? 感謝

+0

的'ItemDataBound'方法被稱爲* *後該項目已被任何額外的邏輯產生。跳過事件沒有任何影響。你是否試圖完全放棄這些行? – mellamokb 2013-03-01 15:13:28

+0

是的,確切地說。我嘗試也返回而不是存在的子,但它沒有工作 – user1187282 2013-03-01 15:21:42

+0

嘗試「如果e.Item.ItemIndex> = 4然後」但這將只是防止這些項目的數據綁定(不模板,和itemcreated處理) – jbl 2013-03-01 15:26:12

回答

0

我認爲你需要嘗試itemCreadedOnDatabound事件

+0

我試過了,但它沒有在這裏工作是我做的。受保護的子rptCol_ItemCreated(發送者爲對象,例如作爲RepeaterItemEventArgs)把手rptCol.ItemCreated 如果e.Item.ItemIndex = 3然後 退出小組 結束如果結束 子 – user1187282 2013-03-01 15:22:32

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 
+0

我想不退出功能只跳過該項目時,它是可能< – user1187282 2013-03-01 15:45:58

2

就像@馬庫斯說的那樣,迭代將繼續,因爲它被調用的每一行。

嘗試不同的方法。在綁定到中繼器之前更改您的數據源。事情是這樣的:

//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(); 
+0

@ user1187282:你有沒有解決你遇到的問題? – 2013-03-22 16:10:52

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) 
相關問題