Finding Controls inside of a nested repeater.

Category : VB.Net

This one almost killed me… I have a nested repeater and could not for the life of me figure out how to find the controls in the nested repeater…

I was doing ONE thing wrong… instead of placing the ItemDataBound event declaration in the Parents ItemDataBound event… I had to put it in the ItemCreated event… and that was it.  After that I could easily find my controls.

Protected Sub RepeaterPARENT_ItemCreated(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs) Handles RepeaterPARENT.ItemCreated
 
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
            Dim repeaterCHILD As Repeater = New Repeater
            repeaterCHILD = TryCast(e.Item.FindControl("RepeaterCHILD"), Repeater)
            AddHandler repeaterCHILD.ItemDataBound, AddressOf repeaterCHILD_ItemDataBound
        End If
End Sub
 
Protected Sub repeaterCHILD_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.RepeaterItemEventArgs)
 
   If e.Item.ItemType = ListItemType.Header Then
            Qty = 0.0
   End If
 
   If CType(e.Item.FindControl("HiddenQuantity"), HiddenField) IsNot Nothing Then
            Dim HiddenQuantity As HiddenField = CType(e.Item.FindControl("HiddenQuantity"),
 HiddenField)
            Qty += CDbl(HiddenQuantity.Value)
   End If
 
   If CType(e.Item.FindControl("LabelQTYSubtotal"), Label) IsNot Nothing Then
            Dim LabelNew As Label = New Label
            LabelNew = CType(e.Item.FindControl("LabelQTYSubtotal"), Label)
            LabelNew.Text = Qty.ToString
   End If
End Sub

Post a comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word