BackColor property not working

7 posts, 0 answers
  1. Dani
    Dani avatar
    20 posts
    Member since:
    Dec 2011

    Posted 12 Dec 2011 Link to this post

    I'm reading the appointments form a datatable. Here is my code:

               List<MyClass> myObjects = (from e in myEntities.Mytable where
                                      e.DateFrom >= schedulerInfo.ViewStart &&
                                      e.DateTo <= schedulerInfo.ViewEnd
                                      select e).ToList();


                List<Appointment> appointments = new List<Appointment>(myObjects.Count);
                foreach (MyClass e in myObjects) {
                    Appointment a = new Appointment();
                    a.ID = e.ID;
                    a.Subject = e.Description;
                    a.Start = e.DateFrom;
                    a.End = e.DateTo;
                    a.BackColor = System.Drawing.Color.Yellow;
                    appointments.Add(a);


    and when I run it, it isn't yellow!
  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 12 Dec 2011 Link to this post

    Hello Dani,

    You need to use Custom Attributes to store the BackColor value and then handle AppointmentDataBound to set the BackColor property for the appointment from its custom attribute. You can see this demo as reference - http://demos.telerik.com/aspnet-ajax/scheduler/examples/advancedformtemplate/defaultcs.aspx.


    Greetings, 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
  3. Dani
    Dani avatar
    20 posts
    Member since:
    Dec 2011

    Posted 13 Dec 2011 Link to this post

    I added the AppointmentDataBound event but it never gets called.
    I put breakpoint in its beginning and it's never hit.
  4. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 13 Dec 2011 Link to this post

    Hello Dani,

    AppointmentDataBound will not fire if you use a Web Service to populate RadScheduler. In this case you should handle OnClientAppointmentDataBound like this:
    function OnClientAppointmentDataBound(sender, eventArgs) {
               var app = eventArgs.get_appointment();
               //debugger;
               var backColor = app.get_attributes().getAttribute("AppointmentColor");
     
               if (backColor)
                   app.set_backColor(backColor);
     
               app.set_borderColor("black");
               app.set_borderWidth("1");
           }

    You can download a working sample from here (WebServiceBinding).


    Greetings, 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
  5. Dani
    Dani avatar
    20 posts
    Member since:
    Dec 2011

    Posted 13 Dec 2011 Link to this post

    Thanks very much for your response.

    I now have another problem.

    Here is the code for my method:

    <script type="text/javascript">
               function OnClientAppointmentDataBound(sender, eventArgs) {
                  var app = eventArgs.get_appointment();
                   if (app.get_attributes().getAttribute("myAttr") == false.toString()) {
                       app.set_borderColor("black");
                       app.set_borderWidth("1");
                   }
           }

            </script>

    and it isn't working!
    What I'm trying to do is set every cell which has myAttribute == true, set its background color to red.
  6. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 13 Dec 2011 Link to this post

    Hello Dani,

    Can you modify the sample from the code library entry so that the problem occurs and send it back to us to inspect it. We need to have a working sample to test to be able to say what is causing the problem.


    Best wishes, 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
  7. Dani
    Dani avatar
    20 posts
    Member since:
    Dec 2011

    Posted 13 Dec 2011 Link to this post

    Actually your previous answer worked. Tnx :)
Back to Top