DropDownTree HeaderTemplate dynamic

6 posts, 0 answers
  1. Jerome MAILLEY
    Jerome MAILLEY avatar
    17 posts
    Member since:
    Jul 2009

    Posted 11 Oct Link to this post

    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>

  2. Jerome MAILLEY
    Jerome MAILLEY avatar
    17 posts
    Member since:
    Jul 2009

    Posted 11 Oct in reply to Jerome MAILLEY Link to this post

    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; }
    }
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Jerome MAILLEY
    Jerome MAILLEY avatar
    17 posts
    Member since:
    Jul 2009

    Posted 11 Oct Link to this post

    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

  5. Ivan Danchev
    Admin
    Ivan Danchev avatar
    837 posts

    Posted 13 Oct Link to this post

    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.
  6. Jerome MAILLEY
    Jerome MAILLEY avatar
    17 posts
    Member since:
    Jul 2009

    Posted 13 Oct in reply to Ivan Danchev Link to this post

    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,

     

  7. Ivan Danchev
    Admin
    Ivan Danchev avatar
    837 posts

    Posted 17 Oct Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017