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

Hierarchical datasource and templates

3 Answers 67 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Davis
Top achievements
Rank 1
Davis asked on 22 Sep 2008, 10:48 AM
Hello

I have got a PanelBar to bind to a hierarchical datasource. However I'm not sure how to get this to work with template items.

RadPanelBar1.DataSource = clients; 
RadPanelBar1.DataFieldID = "ID"
RadPanelBar1.DataFieldParentID = "ParentId"
RadPanelBar1.DataTextField = "Label"
RadPanelBar1.DataBind(); 

That produces a PanelBar with default styling and three levels:

Parent Name
- Child Name
  - Child Child Name

Now what I want to be able to do is turn each row into a template field so I style each level differently and add some other stuff, like button or image on each row.

Parent Name [button]
- Child Name [Image]
  - Child Child Name [Textbox]

Thanks for any help you can provide.



3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 22 Sep 2008, 10:52 AM
Hi Davis,

Using databinding and templates for different item levels is not possible. You can however subscribe to the ItemCreated event of the panelbar and add custom controls to the controls collection of the created item.

Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Alex Ruggeri
Top achievements
Rank 1
answered on 29 Apr 2010, 10:29 PM
Can you gve an example of this as I can't get it to work. I am trying to prepend the > symbol to the link created when the databinding occurs.

Cheers

Pete
0
Nikolay Tsenkov
Telerik team
answered on 03 May 2010, 11:59 AM
Hello Alex Ruggeri,

Here is an example that should help you.
The panelbar is bound to an sqlDataSource and we intercept the server-side event OnItemCreated.
Here is the code-behind handler of this event:
protected void RadPanelBar1_ItemCreated(object sender, Telerik.Web.UI.RadPanelBarEventArgs e)
{
    var createdItem = e.Item;
    var owner = createdItem.Owner;
    int levelInHierarchy = 0;
    while (owner != null)
    {
        levelInHierarchy++;
        owner = owner.Owner;
    }
    string color = System.Drawing.Color.Black.ToString();
    switch (levelInHierarchy)
    {
        case 1:
            {
                break;
            }
        case 2:
            {
                createdItem.ForeColor = System.Drawing.Color.Blue;
                color = System.Drawing.Color.Blue.ToString();
                break;
            }
        case 3:
            {
                createdItem.ForeColor = System.Drawing.Color.Red;
                color = System.Drawing.Color.Red.ToString();
                break;
            }
        default:
            {
                createdItem.Text = "!" + createdItem.Text;
                break;
            }
    }
    Response.Write("</br>");
    // templating the line
    string markUp = "<pre>";
    for (int i = 0; i <= levelInHierarchy; i++)
        markUp += "     ";
    markUp += color + "</pre>";
    Response.Write(markUp);
}

Attached is an example (a screenshot) of the output of this handler, right after the page is loaded (the sqlDataSource is connected to the Northwind - MS's sample DB, to table Employees with selected EmployeeID, LastName and ReportsTo columns).

Hope that this will help you!


All the best,
Nikolay Tsenkov
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
PanelBar
Asked by
Davis
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Alex Ruggeri
Top achievements
Rank 1
Nikolay Tsenkov
Telerik team
Share this question
or