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

AppointmentTemplate

1 Answer 131 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
salman
Top achievements
Rank 1
salman asked on 07 Jul 2008, 05:04 PM

Hi,

I want to add templates at run-time.  Could you please let me know where and how would I do that in code insetead of aspx page.  I'm building a server control and cannot use aspx. 

<telerik:Radschdular>
<AppointmentTemplate>
<%# Eval("Subject")%>
<asp:Label runat="server" ID="lbl1" />
</AppointmentTemplate>
</telerik:Radschdular>


I think i need to use this in the code:
RadScheduler1.AppointmentTemplate.InstantiateIn(lbl1);

But, i'm not sure how to use this.  Any help or suggestion would be appereciated.

Thank you,
-Sal

1 Answer, 1 is accepted

Sort by
0
Accepted
T. Tsonev
Telerik team
answered on 09 Jul 2008, 07:26 AM
Hello,

You need to create a class that implements ITemplate. For example:

public class AppTemplate : ITemplate 
    private Literal subject; 
 
    public void InstantiateIn(Control container) 
    { 
        subject = new Literal(); 
        subject.DataBinding += subject_DataBinding; 
 
        Label lbl1 = new Label(); 
        lbl1.ID = "lbl1"
 
        container.Controls.Add(subject); 
        container.Controls.Add(lbl1); 
    } 
 
    private void subject_DataBinding(object sender, EventArgs e) 
    { 
        IDataItemContainer aptContainer = (IDataItemContainer) subject.BindingContainer; 
        subject.Text = HttpUtility.HtmlEncode((string) DataBinder.Eval(aptContainer.DataItem, "Subject")); 
    } 

Then you need to set the template on each PageLoad:

private void Page_Load(object sender, EventArgs e) 
    RadScheduler1.AppointmentTemplate = new AppTemplate(); 
 

I hope this helps.

Regards,
Tsvetomir Tsonev
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Scheduler
Asked by
salman
Top achievements
Rank 1
Answers by
T. Tsonev
Telerik team
Share this question
or