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

PanelBar.ItemTemplate

6 Answers 149 Views
PanelBar
This is a migrated thread and some comments may be shown as answers.
Rahel
Top achievements
Rank 1
Rahel asked on 05 Nov 2008, 11:45 AM
Hello,

how can I create a ItemTemplate on server-side?

I tryed to add it in the OnInit method like this: 

public

 

class FilterPanel : FilterPanelBase {

 

protected override void OnInit(EventArgs e)

{

 

FilterPanelTemplate t = new FilterPanelTemplate();

 

 

Control myContainer = new Control();

t.InstantiateIn(myContainer);

 

this.ItemTemplate = t;
base.OnInit(e);

}

}

 

public

 

class FilterPanelTemplate : ITemplate

 

{

public void InstantiateIn(Control container)

{

 

TextBox _filterInput = new TextBox();

_filterInput.ID =

"_filterInput";

 

_filterInput.Text =

"Suchbegriff...";

 

container.Controls.Add(_filterInput);

}

}

 

It doesn't work.

Thanks for help.

6 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 06 Nov 2008, 06:27 AM
Hi Rahel,

Go through the following help article which explains how to add templates at  runtime.
Adding Templates at run-time

Shinu.
0
Rahel
Top achievements
Rank 1
answered on 06 Nov 2008, 11:10 AM
Hello,

so now I get the added controls, but the controls are shown under the first level. How can I add controls to the first item level(shown in the same line with the collaps-icon)? I tryed to use a div control, too. But it doesnt work.

thanks for support
0
Paul
Telerik team
answered on 06 Nov 2008, 11:42 AM
Hello Rahel,

Please refer to our Templates example for details on the matter.

Greetings,
Paul
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rahel
Top achievements
Rank 1
answered on 06 Nov 2008, 12:11 PM

hello,

I know the example. And if I add my dyn. created controls like this: planitem1.items[0].controls.add(xxx). The controls will be added. But not in the first level row.

 

On code-behinde: added controls are created into the div for template items.....So how can I display the added controls in the same line like the collaps-button.

 

thanks

0
Accepted
Paul
Telerik team
answered on 06 Nov 2008, 12:46 PM
Hi Rahel,

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">  
    div.RadPanelBar .rpItem  
    {  
        position: relative;  
    }  
      
    div.RadPanelBar .rpTemplate  
    {  
        position: absolute; top: 2px; right: 0;  
    }  
    </style> 
</head> 
<body> 
    <form id="form1" runat="server">  
        <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
        <asp:Button ID="Button1" runat="server" Text="Button" /> 
    </form> 
</body> 
</html> 

Code-behind:
protected void Page_Load(object sender, EventArgs e)  
{  
    RadPanelBar panelbar = new RadPanelBar();  
    panelbar.ID = "RadPanelBar1";  
    panelbar.Width = Unit.Pixel(300);  
    form1.Controls.Add(panelbar);  
 
    if (!IsPostBack)  
    {  
        RadPanelItem panel1 = new RadPanelItem("root1");  
        panelbar.Items.Add(panel1);  
 
        RadPanelItem Child1 = new RadPanelItem("Child1");  
        panel1.Items.Add(Child1);  
 
        RadPanelItem Child2 = new RadPanelItem("Child2");  
        panel1.Items.Add(Child2);  
    }  
 
    TextBox tb = new TextBox();  
    tb.Text = "test";  
    tb.CssClass = "test";  
    panelbar.Items[0].Controls.Add(tb);  


Kind regards,
Paul
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rahel
Top achievements
Rank 1
answered on 06 Nov 2008, 02:29 PM

Thanks for support and for the last code!

greetings,

 

rahel

Tags
PanelBar
Asked by
Rahel
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Rahel
Top achievements
Rank 1
Paul
Telerik team
Share this question
or