Setting, RadScheduler ResourceHeaderTemplate in code

2 posts, 0 answers
  1. Arvind
    Arvind avatar
    12 posts
    Member since:
    Jun 2012

    Posted 13 Jun 2012 Link to this post

    Hi,

    I need to create a rasScheduler dynamically from code, I need to change the header template is it possible to replicate the below snippet in code and assign it to the scheduler dynamically.


    <ResourceHeaderTemplate>
        <asp:Panel ID="ResourceWrapper" runat="server">
            <asp:Label ID="AgentLabel" runat="server" Text='<%# Eval("Text") %>' />
        </asp:Panel>
    </ResourceHeaderTemplate>

    Thanks

    Arvind
  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 18 Jun 2012 Link to this post

    Hello Arvind,

    Please, try the following code and let me know if you have further questions:

    public partial class RadSchedulerWebForm1 : System.Web.UI.Page
    {
     
        protected void Page_Load(object sender, EventArgs e)
        {
            RadScheduler1.ResourceHeaderTemplate = new ResourceHeaderTemplate();
        }
     
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            RadScheduler1.Provider = new XmlSchedulerProvider(Server.MapPath("~/App_Data/Appointments.xml"), true);
             
        }
     
    }
    public class ResourceHeaderTemplate : ITemplate
    {
        public void InstantiateIn(Control container)
        {
            Label textLabel = new Label();
            textLabel.ID = "AgentLabel";
            textLabel.DataBinding += new EventHandler(textLabel_DataBinding);
             
            Panel resourceWrapper = new Panel();
            resourceWrapper.ID = "ResourceWrapper";
     
            resourceWrapper.Controls.Add(textLabel);
            container.Controls.Add(resourceWrapper);
        }
     
        void textLabel_DataBinding(object sender, EventArgs e)
        {
            Label resourceText = (Label)sender;
            resourceText.Text = ((SchedulerResourceContainer)resourceText.Parent.Parent).Resource.Text;       
        }   
    }


    Kind regards,
    Peter
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top