Add textbox to panel level through code behind

3 posts, 0 answers
  1. Jeff
    Jeff avatar
    38 posts
    Member since:
    Jan 2008

    Posted 08 Jan 2009 Link to this post

    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. Paul
    Admin
    Paul avatar
    4281 posts

    Posted 10 Jan 2009 Link to this post

    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.
  3. Jeff
    Jeff avatar
    38 posts
    Member since:
    Jan 2008

    Posted 11 Jan 2009 Link to this post

    Thanks for the code sample - worked great!
Back to Top