Accessing DataItems in OnItemCreated

2 posts, 0 answers
  1. Charles
    Charles avatar
    30 posts
    Member since:
    Feb 2013

    Posted 08 Apr 2015 Link to this post

    I have a radPanelBar that is is bound to an SqlDataSource. Normally I would use findcontrol in the OnItemDataBound event to access the controls in the template as follows:

     

    Private Sub rpbVehicles_ItemDataBound(sender As Object, e As RadPanelBarEventArgs) Handles rpbVehicles.ItemDataBound
     
           Dim imgThumb As Image = e.Item.FindControl("imgThumb")
     
    End Sub

    But apparently ItemDataBound is too early in the cycle to access controls as findcontrol always returns Nothing.

    I can access the controls in the ItemCreated event, but how do I access the DataItems there?

    I want to do something like:

    Private Sub rpbVehicles_ItemCreated(sender As Object, e As RadPanelBarEventArgs) Handles rpbVehicles.ItemCreated
     
    Dim vehicleID As Integer = e.Item.DataItem("ItemID")
    Dim cbShow As CheckBox = e.Item.FindControl("cbShow")
    cbShow.Attributes.Add("VehicleID", vehicleID.ToString)
     
    End Sub

     

    How do I access the DataItems?

     

    Thanks

     

    Charles

     

  2. Ivan Danchev
    Admin
    Ivan Danchev avatar
    835 posts

    Posted 10 Apr 2015 Link to this post

    Hello,

    Please, find attached a sample project, which demonstrates how to access (in the ItemDataBound event handler) a control embedded in a RadPanelBar ItemTemplate. The ItemCreated event is not the right place to do that because if the RadPanelBar is bound to a data source, this event occurs before any data binding occurs, before any properties have been set to reflect the data from the data source.

    In the sample project we access an asp:Button control and change the value of its Text property in the ItemDataBound event handler. The Telerik .dll files are deleted from the bin folder in order not to exceed the maximum allowed attachment size.

    Regards,
    Ivan Danchev
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top