Binding Telerik RadPanelBar to a data source of type which implements IEnumerable such as Array or ArrayList is flat databinding because only root items are created and there is no hierarchy.
Here is a general outline of such databinding:
- Create the collection.
- Add string values to the collection and set the DataSource property of Telerik RadPanelBar to the instance of the collection.
- Call the DataBind() method.
The text from the collection is then automatically mapped to the Text property of the respective panelbar item.
If you have a collection (ArrayList, array or in fact any collection implementing ICollection or IEnumerable) that contains objects (as opposed to string values), you can take advantage of the DataTextField, DataNavigateUrlField, and the DataValueField properties to map a property from the object directly to the Text, NavigateUrl or Value fields.
If you need to map additional properties from the object to other properties of the respective panelbar item, you have to subscribe to the ItemDataBound event. The event arguments passed to the event, e.Item and e.Item.DataItem, hold the instance of the panelbar item being bound and the DataItem associated with the panelbar item. You can then map a property from the DataItem (make sure to cast the DataItem object to your respective data type first) to the property of the RadPanelBarItem class.
Example:
| C# |
Copy Code |
|
private ArrayList GenerateArrayList() { ArrayList itemsList = new ArrayList(); itemsList.Add("One"); itemsList.Add("Two"); itemsList.Add("Three"); return itemsList; } protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { RadPanelBar1.DataSource = GenerateArrayList(); RadPanelBar1.DataBind(); } } |
| VB.NET |
Copy Code |
|
Private Function GenerateArrayList() As ArrayList Dim itemsList As New ArrayList() itemsList.Add("One") itemsList.Add("Two") itemsList.Add("Three") Return itemsList End Function Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack Then RadPanelBar1.DataSource = GenerateArrayList() RadPanelBar1.DataBind() End If End Sub |
See Also