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
Go through the following help article which explains how to add templates at runtime.
Adding Templates at run-time
Shinu.
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
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.
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
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.
Thanks for support and for the last code!
greetings,
rahel