Contents
Licensing
Installation and deployment
DNN
Feature overview
New to Telerik RadPanelBar?
Already using the control
AJAX support
ASP.NET 2.0 features
Data Binding
Telerik RadPanelBar client-side
Telerik RadPanelBar server-side
Example scenarios (How to)
Controlling the visual appearance
Defining the Telerik RadPanelBar structure
Custom Attributes
Templates
Troubleshooting
API Reference
|
|
| DataTable, DataSet or DataView |
Send comments on this topic. |
| See Also |
|
|
Data Binding > DataTable, DataSet or DataView |
Telerik RadPanelBar can be bound to DataTable, DataSet and DataView. Hierarchy can be established with ID->ParentID relation.
The following example illustrates all the key points when binding to DataTable, DataSet or DataView.
We will use a dynamically created DataTable as the data source.
| C# |
Copy Code |
|
private DataTable CreateTestTable() { DataTable table = new DataTable(); table.Columns.Add("ID"); table.Columns.Add("ParentID"); table.Columns.Add("Text"); table.Columns.Add("URL"); table.Columns.Add("Tooltip"); table.Rows.Add(new string[] { "1", null, "root 1", "root1.aspx", "root 1 tooltip" }); table.Rows.Add(new string[] { "2", null, "root 2", "root2.aspx", "root 1 tooltip" }); table.Rows.Add(new string[] { "3", "1", "child 1.1", "child11.aspx", "child 1.1 tooltip" }); table.Rows.Add(new string[] { "4", "1", "child 1.2", "child12.aspx", "child 1.2 tooltip" }); table.Rows.Add(new string[] { "5", "1", "child 1.3", "child13.aspx", "child 1.3 tooltip" }); table.Rows.Add(new string[] { "6", "5", "child 1.3.1", "child131.aspx", "child 1.3.1 tooltip" }); table.Rows.Add(new string[] { "7", "5", "child 1.3.2", "child132.aspx", "child 1.3.2 tooltip" }); table.Rows.Add(new string[] { "8", "5", "child 1.3.3", "child133.aspx", "child 1.3.3 tooltip" }); return table; } |
| VB.NET |
Copy Code |
|
Private Function CreateTestTable() As DataTable Dim table As New DataTable() table.Columns.Add("ID") table.Columns.Add("ParentID") table.Columns.Add("Text") table.Columns.Add("URL") table.Columns.Add("Tooltip") table.Rows.Add(New String() {"1", Nothing, "root 1", "root1.aspx", "root 1 tooltip"}) table.Rows.Add(New String() {"2", Nothing, "root 2", "root2.aspx", "root 1 tooltip"}) table.Rows.Add(New String() {"3", "1", "child 1.1", "child11.aspx", "child 1.1 tooltip"}) table.Rows.Add(New String() {"4", "1", "child 1.2", "child12.aspx", "child 1.2 tooltip"}) table.Rows.Add(New String() {"5", "1", "child 1.3", "child13.aspx", "child 1.3 tooltip"}) table.Rows.Add(New String() {"6", "5", "child 1.3.1", "child131.aspx", "child 1.3.1 tooltip"}) table.Rows.Add(New String() {"7", "5", "child 1.3.2", "child132.aspx", "child 1.3.2 tooltip"}) table.Rows.Add(New String() {"8", "5", "child 1.3.3", "child133.aspx", "child 1.3.3 tooltip"}) Return table End Function |
 |
The ParentID of the root items must be null (nothing). If for some reason the data source comes without null values for the ParentID column, the solution is to create a query that returns the expected value (null). For example:
SELECT ID, Text, IF(ParentID = 0, NULL, ParentID) FROM tblData
The above code shows how to convert ParentID= 0 to ParentID=null
Another approach is to load the data source into a data table and modify the ParentID values of the table. |
Bind the control, establish hierarchy and set the Text, Value and NavigateUrl properties:
| C# |
Copy Code |
|
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { RadPanelBar1.DataSource = CreateTestTable(); //Establish hierarchy: RadPanelBar1.DataFieldID = "ID"; RadPanelBar1.DataFieldParentID = "ParentID"; //Set Text, Value, and NavigateUrl: RadPanelBar1.DataTextField = "Text"; RadPanelBar1.DataValueField = "ID"; RadPanelBar1.DataNavigateUrlField = "URL"; RadPanelBar1.DataBind(); } } |
| VB.NET |
Copy Code |
|
Protected Sub Page_Load(sender As Object, e As EventArgs) If Not IsPostBack Then RadPanelBar1.DataSource = CreateTestTable() RadPanelBar1.DataFieldID = "ID" RadPanelBar1.DataFieldParentID = "ParentID" RadPanelBar1.DataTextField = "Text" RadPanelBar1.DataValueField = "ID" RadPanelBar1.DataNavigateUrlField = "URL" RadPanelBar1.DataBind() End If End Sub |
To set additional properties subscribe to the ItemDataBound event and use the following method:
| C# |
Copy Code |
|
protected void RadPanelBar1_ItemDataBound(object sender, RadPanelBarEventArgs e) { //Set additional properties. ToolTip for example: DataRowView row = (DataRowView)e.Item.DataItem; e.Item.ToolTip = row["Tooltip"].ToString(); } |
| VB.NET |
Copy Code |
|
Protected Sub RadPanelBar1_ItemDataBound(sender As Object, e As RadPanelBarEventArgs) Dim row As DataRowView = CType(e.Item.DataItem, DataRowView) e.Item.ToolTip = row("Tooltip").ToString() End Sub |
See Also
|