ItemCloned event not firing
-
2008年6月27日 19:38When does the ItemCloned event fire? I have a combobox control in a datarepeater control. I read about needing the ItemCloned event because the combobox acts flaky without it. The combobox is still flaky even with this event. I set a debug stop in the coding and noticed that the event never gets fired. Am I missing some coding? There is no other event for the datarepeater in my app except for the ItemCloned. Here's the code:
Dim Source As ComboBox = _
CType(DataRepeater1.ItemTemplate.Controls.Item("cboSponsoringAgency"), ComboBox) Dim ComboBox1 As ComboBox = _
CType(e.DataRepeaterItem.Controls.Item("cboSponsoringAgency"), ComboBox) For Each s As String In Source.Items
ComboBox1.Items.Add(s)
Next
Thanks for any help or advice.
全部回复
-
2008年6月28日 0:29
The ItemCloned event will fire as the DataRepeater is cloning the controls from the template for each additional DataRepeaterItem. Check to make sure the handles (i.e. Handles DataRepeater1.ItemCloned) clause on the event is correct and it should fire.
John Hart (Microsoft)- 已建议为答案 YangCaoMicrosoft Employee, Moderator 2008年7月1日 6:58
- 已标记为答案 Martin Xie - MSFT 2008年7月2日 8:14
-
2012年4月12日 13:03
The ItemCloned event does not seem to be firing for each item. I have a list with 17 items but it is only firing 6 times. I put a static integer variable in the event handler and increment it each time and did a console.writeline showing its value, but it only displays 6 times. The datarepeater shows all 17 items, but the ItemCloned event only fired 6 times.
I was also wanting to find some index of the cloned item, but was unable to find anything useful. Here is my code and its output:
Private Sub DataRepeater1_ItemCloned(sender As Object,
e As Microsoft.VisualBasic.PowerPacks.
DataRepeaterItemEventArgs) Handles DataRepeater1.ItemCloned
Static i As Integer = 0
Console.WriteLine("i " & i.ToString)
i += 1
Console.WriteLine("e.DataRepeaterItem.ItemIndex " &
e.DataRepeaterItem.ItemIndex.ToString)
Console.WriteLine("DataRepeater1.ItemTemplate.ItemIndex " &
DataRepeater1.ItemTemplate.ItemIndex.ToString)
End Sub(I inserted line breaks in the code because it was not displaying correctly on this screen.)
i 0
e.DataRepeaterItem.ItemIndex 0
DataRepeater1.ItemTemplate.ItemIndex 0
i 1
e.DataRepeaterItem.ItemIndex 0
DataRepeater1.ItemTemplate.ItemIndex 0
i 2
e.DataRepeaterItem.ItemIndex 0
DataRepeater1.ItemTemplate.ItemIndex 0
i 3
e.DataRepeaterItem.ItemIndex 0
DataRepeater1.ItemTemplate.ItemIndex 0
i 4
e.DataRepeaterItem.ItemIndex 0
DataRepeater1.ItemTemplate.ItemIndex 0
i 5
e.DataRepeaterItem.ItemIndex 0
DataRepeater1.ItemTemplate.ItemIndex 0
i 6
e.DataRepeaterItem.ItemIndex 0
DataRepeater1.ItemTemplate.ItemIndex 0

