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

DropDownTree HeaderTemplate dynamic

5 Answers 120 Views
DropDownTree
This is a migrated thread and some comments may be shown as answers.
Jerome MAILLEY
Top achievements
Rank 1
Jerome MAILLEY asked on 11 Oct 2016, 09:33 AM

Hi,

First of all, I'm using the latest version of your Telerik.Web.UI.dll (2016.3.914.40). I'm trying to set RadDropDownTree HeaderTemplate dynamically as I did for RadComboBox. Here is my code :

 

<telerik:RadDropDownTree ID="RadDropDownTree" runat="server" EnableViewState="false" CheckBoxes="None"      OnNodeDataBound="RadDropDownTree_NodeDataBound" <br>    DataFieldID="ID" DataFieldParentID="ParentID" DataTextField="Text" DataValueField="Value"<br>    Width="100%" RenderMode="Lightweight" Visible="false" Skin="Metro"><br></telerik:RadDropDownTree>

5 Answers, 1 is accepted

Sort by
0
Jerome MAILLEY
Top achievements
Rank 1
answered on 11 Oct 2016, 09:42 AM
protected void Page_Load(object sender, EventArgs e){
//....
RadDropDownTree.HeaderTemplate = new HeaderTemplate(headerItem);
//....
}
 
public class HeaderTemplate : ITemplate {
ComboBoxItem _headerItem;
public HeaderTemplate(ComboBoxItem headerItem) {
this._headerItem = headerItem;
}
public void InstantiateIn(Control container) {
if (!string.IsNullOrEmpty(_headerItem.Code))
{
Label labelCode = new Label();
labelCode.Font.Bold = true;
labelCode.Text = _headerItem.Code;
container.Controls.Add(labelCode);
Label labelDash = new Label();
labelDash.Text = " - ";
container.Controls.Add(labelDash);
}
Label labelLabel = new Label();
labelLabel.Font.Italic = true;
labelLabel.Text = _headerItem.Label;
container.Controls.Add(labelLabel);
}
}
public class ComboBoxItem{
public string Code { get; set; }
public string Label { get; set; }
}
0
Jerome MAILLEY
Top achievements
Rank 1
answered on 11 Oct 2016, 09:45 AM

However, it's does not work. Its seems that ITemplate is not made for RadDropDownTree HeaderTemplate : the InstantiateIn function is never called. Is there a way to make it work ?

 

Thanks

0
Ivan Danchev
Telerik team
answered on 13 Oct 2016, 07:51 AM
Hello Jerome,

The DropDownTree is initialized earlier, thus its HeaderTemplate has to be set earlier than the page's Load event - in the PreInit event:
protected void Page_PreInit(object sender, EventArgs e)
{
    RadDropDownTree1.HeaderTemplate = new HeaderTemplate(headerItem);
}



Regards,
Ivan Danchev
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
0
Jerome MAILLEY
Top achievements
Rank 1
answered on 13 Oct 2016, 02:49 PM

Hello Ivan,

I cannot use the Page_PreInit function because the RadDropDownTree is in a UserControl so it's not fired.

According to this, I tried the following code but it does not work either:

protected void Page_Init(object sender, EventArgs e)
{
    RadDropDownTree1.HeaderTemplate = new HeaderTemplate(headerItem);
}

 

I hope you will help me to figure it out.

Thanks,

 

0
Ivan Danchev
Telerik team
answered on 17 Oct 2016, 02:42 PM
Hello Jerome,

As I explained in my previous reply, due to the early initialization of the DropDownTree the template must be set in the PreInit event. Both the Init and Load events are fired too late, thus neither the main page's nor the  UserControl's Init and Load events are not suitable for setting the template.

Regards,
Ivan Danchev
Telerik by Progress
Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Tags
DropDownTree
Asked by
Jerome MAILLEY
Top achievements
Rank 1
Answers by
Jerome MAILLEY
Top achievements
Rank 1
Ivan Danchev
Telerik team
Share this question
or