This is a migrated thread and some comments may be shown as answers.

Accessing DataItems in OnItemCreated

1 Answer 48 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Charles
Top achievements
Rank 1
Charles asked on 08 Apr 2015, 08:43 PM

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

 

1 Answer, 1 is accepted

Sort by
0
Ivan Danchev
Telerik team
answered on 10 Apr 2015, 12:27 PM
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.

 
Tags
PanelBar
Asked by
Charles
Top achievements
Rank 1
Answers by
Ivan Danchev
Telerik team
Share this question
or