Finding controls within "AppointmentTemplate"

6 posts, 0 answers
  1. prashanth_t
    prashanth_t avatar
    10 posts
    Member since:
    Apr 2009

    Posted 20 Apr 2009 Link to this post

    I'm using a Rad Scheduler. Setting the datasource through programming. In the appointment template I've defined 5 labels. For each day the appointment template would carry these 5 labels. However there will be difference in the data it carries and the formatting of the labels too will be different for different criteria. I'm able to get/set the data, but not able to do the formatting.
    Given below is the aspx syntax.

     


     

    <telerik:RadScheduler ID="RadScheduler2" runat="server" DataEndField="DutyEnd"   
     
    DataKeyField="Id" DataStartField="DutyStart" CustomAttributeNames="HoursPerDay" 
     
    DataSubjectField="Date"   
     
    onappointmentcommand="RadScheduler2_AppointmentCommand"   
     
    onappointmentdatabound="RadScheduler2_AppointmentDataBound"   
     
    onformcreated="RadScheduler2_FormCreated">  
     
    <AppointmentTemplate> 
     
    <asp:Label Text='<%# Bind("HoursPerDay") %>' runat="server" ID="lblTest"></asp:Label><br /> 
     
    <asp:Label Text="This is a test2" runat="server" ID="Label8"></asp:Label><br /> 
     
    <asp:Label Text="This is a test3" runat="server" ID="Label9"></asp:Label><br /> 
     
    <asp:Label Text="This is a test4" runat="server" ID="Label10"></asp:Label><br /> 
     
    <asp:Label Text="This is a test5" runat="server" ID="Label11"></asp:Label><br /> 
     
    </AppointmentTemplate> 
     
    </telerik:RadScheduler> 
     
     

    On code behind I'm able to set the value as shown below. 

     

    protected void RadScheduler2_AppointmentDataBound(object sender, SchedulerEventArgs e)  
            {  
    e.Appointment.Attributes["HoursPerDay"] = "Value from DB";  

    However In addition to this I would like to do formatting on the labels based on certain criteria. For example for the label "lblTest" need to set the font color to Red, set the visible property of the label to "true/false", etc............. Basically I need a way to find out the control within the appointment template.

    I'm unable to do this. Appreciate if some one could let me know how to achieve this (please provide with some code sample)

    Thank you.

  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 20 Apr 2009 Link to this post

    Hi prashanth_t,

    You could add additional custom attributes to carry the formatting information such as "BacgroundColorCustomAttribute" or "FontColorCustomAttribute". The approach is exactly the same that you have already done for the label's Text with  the "HoursPerDay" attribute.


    Kind regards,
    Peter
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. prashanth_t
    prashanth_t avatar
    10 posts
    Member since:
    Apr 2009

    Posted 21 Apr 2009 Link to this post

    Hi Peter,
    Thanks for your reply.
    I tried your suggestion. With some minor adjustment I was able to set the visible property of the control within the "AppointmentTemplate". However setting formatting information (ForeColor, Backcolor) is not successful.

    The following works.

     

    e.Appointment.Attributes[

    "CustomVisibility"] = "false";  

     

     

     

    Visible='<%# Convert.ToBoolean(Eval("CustomVisibility")) %>'

    However the following fails. It throws a runtime exception ("Specified cast is not valid").
    e.Appointment.Attributes["CustomForeColor"] = "Red";
    ForeColor='<%# Eval("CustomForeColor") %>' 

    (I may be missing some thing; please let me know if you have a work around)

    Also, I want to add another question. In my project the RadScheduler is used only to display information(using specifically for the calendar view).
    Is it possible to expand area based on the content. For eample if I'm displaying 10 labels (one in each line seperated by line breaks), I want this information to be available in all views.

    In the day view it is OK (unless the duration between the starttime(startdate) and endtime(enddate) are just one or two hours.
    In the "week view" the data is getting sqeezed so that I can only see part of the information.
    In the "Month view" it just partially displays the first label info.

    I tried using panel with scroll bars enabled (it doesn't help a lot). It would be great if there is a way to resize the calendar view based on the information contained within. Appreciate if you can let me know if there are any properties to achieve this in RadScheduler.

    Thank you.
  4. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 22 Apr 2009 Link to this post

    Hello prashanth,

    Please, review this help topic on custom attributes and resources:
    http://www.telerik.com/help/aspnet-ajax/schedule_designcustomresourcesandattributes.html
    I hope you find it helpful.

    As for the other question, please consider using the RowHeight property.


    All the best,
    Peter
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Graham MacLeod
    Graham MacLeod avatar
    7 posts
    Member since:
    Oct 2009

    Posted 17 Apr 2013 Link to this post

    I'm am using a much later version (2013.1.220.40) but getting the exact same 'Specified cast is not valid' error using this code:

    <asp:Label ID="CompanyName" runat="server" Text='<%# Eval("CompanyName") %>' ForeColor='<%# Eval("TextColor") %>'></asp:Label>

    My text colors are hexadecimal codes, e.g. '#000000'.

    Also, the hyperlink for "help topic on custom attributes and resources:" that Prashanth provides is broken.

    Quick update: changed the line as follows:

    <asp:Label ID="CompanyName" runat="server" Text='<%# Eval("CompanyName") %>' ForeColor='<%# System.Drawing.ColorTranslator.FromHtml(Eval("TextColor")) %>'></asp:Label>


    but this gives new error:

    Compiler Error Message: CS1502: The best overloaded method match for 'System.Drawing.ColorTranslator.FromHtml(string)' has some invalid arguments

    My "TextColor" attribute definitely has a valid hex string for a color.

  6. Plamen
    Admin
    Plamen avatar
    3080 posts

    Posted 22 Apr 2013 Link to this post

    Hi Graham ,

     
    You can try to set the desired ForeColor in the code behind in the RadScheduler1_AppointmentCreated event as for example the appointmenttempalte is customized in this on-line demo.

    As for the broken link -this is the right one by I do not think it will be helpful in this case.

    Hope this information will be helpful.

    Greetings,
    Plamen
    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