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

Add textbox to panel level through code behind

2 Answers 127 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Jeff
Top achievements
Rank 1
Jeff asked on 08 Jan 2009, 08:52 PM
We have a 3 level radpanel that is built dynamically from a database. At the third level of the radpanel hierarchy we need to add a textbox that we can populate and retrieve data from.

So for example:

Employee Salaries
-- Managers
------ John [ textbox ]
------ Mary [ textbox ]
-- Executives
------ Harry [textbox ]
Building Costs
-- Building 1
------ Heat [ textbox ]

etc.

Is there a way to do this?

thanks

2 Answers, 1 is accepted

Sort by
0
Paul
Telerik team
answered on 10 Jan 2009, 04:18 PM
Hello Jeff,

Please find below a sample code snippet that shows the needed approach.

ASPX:
<html xmlns="http://www.w3.org/1999/xhtml"
<head runat="server"
    <title>Untitled Page</title> 
    <style type="text/css"
    .rpTemplate 
    { 
        padding-left: 20px !important; 
    } 
    </style> 
</head> 
<body> 
    <form id="form1" runat="server"
        <asp:ScriptManager ID="ScriptManager1" runat="server"
        </asp:ScriptManager> 
        <telerik:RadPanelBar ID="RadPanelBar1" runat="server" DataSourceID="SqlDataSource1" DataFieldID="id" DataFieldParentID="parentId" DataTextField="Text" OnItemDataBound="RadPanelBar1_ItemDataBound"
            <CollapseAnimation Duration="100" Type="None" /> 
            <ExpandAnimation Duration="100" Type="None" /> 
        </telerik:RadPanelBar> 
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Links]"></asp:SqlDataSource> 
    </form> 
</body> 
</html> 
 

Code-behind:
using System; 
using System.Data; 
using System.Configuration; 
using System.Collections; 
using System.Web; 
using System.Web.Security; 
using System.Web.UI; 
using System.Web.UI.WebControls; 
using System.Web.UI.WebControls.WebParts; 
using System.Web.UI.HtmlControls; 
 
public partial class _Default : System.Web.UI.Page 
    protected void Page_Load(object sender, EventArgs e) 
    { 
             
    } 
    protected void RadPanelBar1_ItemDataBound(object sender, Telerik.Web.UI.RadPanelBarEventArgs e) 
    { 
        if (e.Item.Level == 2) 
        { 
             
            Label lb = new Label(); 
            lb.Text = e.Item.Text; 
            e.Item.Controls.Add(lb); 
 
            TextBox tb = new TextBox(); 
            tb.Text = e.Item.Text; 
            tb.Width = Unit.Pixel(50); 
            e.Item.Controls.Add(tb); 
 
            e.Item.Text = ""
        } 
    } 
 


All the best,
Paul
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jeff
Top achievements
Rank 1
answered on 11 Jan 2009, 06:12 AM
Thanks for the code sample - worked great!
Tags
PanelBar
Asked by
Jeff
Top achievements
Rank 1
Answers by
Paul
Telerik team
Jeff
Top achievements
Rank 1
Share this question
or