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

Databind in a panelbar item

3 Answers 82 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Jonathan
Top achievements
Rank 1
Jonathan asked on 29 May 2008, 11:01 AM
I have a panel bar with 3 items.

In each item I have different templates, I want to databind different datasources to these items but I can't figure it out.

PanelBar.FindItemByValue(

"Offices").DataItem = Office

That is what I'm trying at the moment in a for loop but it doesn't add all the offices, only the last one.

How can I do this? I can't use .Item.Add because I need to use the template.

Cheers

3 Answers, 1 is accepted

Sort by
0
Paul
Telerik team
answered on 29 May 2008, 11:25 AM
Hi Jonathan,

Actually, there's an easy way in which you can achieve your goal - use UserControl for the templated controls. Here's a sample code snippet that shows the needed approach.

ASPX:
<form id="form1" runat="server">     
    <asp:ScriptManager ID="scrMgr" runat="server">     
    </asp:ScriptManager>    
    <div>    
        <telerik:RadPanelBar ID="thePanelBar" runat="server" Skin="Office2007" Width="500">     
        </telerik:RadPanelBar>    
    </div>    
    <asp:Button ID="btnSubmit" runat="server" Text="Save Users' Data" />    
</form>    
 

Code-behind;
using System.Data;  
using System.Data.SqlClient;  
using Telerik.Web.UI;  
 
partial class test2 : System.Web.UI.Page  
{  
 
    private DataTable data {  
        get {  
            DataTable dt = new DataTable();  
            dt.Columns.Add(new DataColumn("ID"typeof(string)));  
            dt.Columns.Add(new DataColumn("ParentID"typeof(string)));  
            dt.Columns.Add(new DataColumn("NAME"typeof(string)));  
            dt.Rows.Add(new string[] {"pitem1"null"Sakis"});  
            dt.Rows.Add(new string[] {"pitem2"null"Makis"});  
            dt.Rows.Add(new string[] {"pitem3"null"Lakis"});  
            dt.Rows.Add(new string[] {"pitem4""pitem1"null});  
            dt.Rows.Add(new string[] {"pitem5""pitem2"null});  
            dt.Rows.Add(new string[] {"pitem6""pitem3"null});  
            return dt;  
        }  
    }  
 
    protected void Page_Load(object sender, System.EventArgs e)  
    {  
        if (!IsPostBack)  
        {  
            thePanelBar.DataTextField = "NAME";  
            thePanelBar.DataFieldID = "ID";  
            thePanelBar.DataFieldParentID = "ParentID";  
            thePanelBar.DataSource = data;  
            thePanelBar.DataBind();  
        }  
 
        foreach (RadPanelItem myPanelItem in thePanelBar.Items)  
        {  
            myPanelItem.Items(0).Controls.Add(LoadControl("~/WebUserControl.ascx"));  
        }  
    }  
 
    protected void btnSubmit_Click(object sender, System.EventArgs e)  
    {  
        foreach (RadPanelItem p in thePanelBar.Items)  
        {  
            Response.Write(p.Items(0).Controls.Count + "<br />");  
        }  
    }  
}  
 



All the best,
Paul
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Jonathan
Top achievements
Rank 1
answered on 29 May 2008, 11:30 AM
I'm not sure that will work in this case because I need to update other panel bars depending on what is selected. i.e. if I select two offices in the panelbar then I need the staff option to update with staff from that office

office>
    list of offices (OfficeName CheckBox)
staff>
    list of staff from selected offices above

Hope that makes sense
0
Paul
Telerik team
answered on 29 May 2008, 11:33 AM
Hello Jonathan,

Unfortunately, the provided information does not help us much in reproducing the error. I'm afraid we could not be of much help unless we reproduce the issue on our side. It will be best if you can open a support ticket and send us a simple running project (incl. your custom skin, CSS, images, DB backup if needed and so on) demonstrating the problem (and step-by-step instructions on doing so). In that way we can reproduce and pinpoint the problems you're facing on our side, understand the logic of your application and provide a solution.

Sincerely yours,
Paul
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
PanelBar
Asked by
Jonathan
Top achievements
Rank 1
Answers by
Paul
Telerik team
Jonathan
Top achievements
Rank 1
Share this question
or