set backcolor for Appointment

8 posts, 0 answers
  1. datisgod
    datisgod avatar
    17 posts
    Member since:
    Mar 2007

    Posted 08 Oct 2007 Link to this post

    i writed method for fill data to Scheduler

    private
    void loadData(int ResourceID) {

    DataTable dtSource = RegistrationDB.GetWithStatusAndResource("A", ResourceID);

    RSFilm.DataSource = dtSource;

    RSFilm.DataStartField = "Registration_From";

    RSFilm.DataEndField = "Registration_To";

    RSFilm.DataKeyField = "Registration_ID";

    RSFilm.DataSubjectField = "Film_Title";

    RSFilm.DataBind();

    }

    then how i can set backcolor for Appointment of RsFilm(Scheduler)? example : when i have '007' film, it will display backcolor is yellow on scheduler or 'titanic' Film is red, 'Death Dealers' is green ..... , thanks

  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 08 Oct 2007 Link to this post

    Hello Dao,

    Thank you for your interest in RadScheduler.

    You can differentiate by Subject and set the CssClass property of the Appointment in the AppointmentCreated event. For example:

    protected void RadScheduler1_AppointmentCreated(object sender, AppointmentCreatedEventArgs e)  
        {  
                          
                if (e.Appointment.Subject == "007")  
                {  
                    e.Appointment.CssClass = "CustomYellow";                  
                }              
                  
        } 

    Also the CustomYellow class should be defined as follows:
    <head runat="server">  
    <style type="text/css">  
    .RadScheduler_[MySkin] .rsApt.CustomYellow .rsAptInner  
    {  
        background: yellow;  
    }  
    </style> 

    This is because of the way RadScheduler is rendered.

    If you have further questions, feel free to ask us. We will be glad to help you.


    Best wishes,
    Peter
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. datisgod
    datisgod avatar
    17 posts
    Member since:
    Mar 2007

    Posted 08 Oct 2007 Link to this post

    Dear Peter !

    in my table have 'Film_Color' and 'Film_Name' , i want to get 'film_color' for Appointment background, not fix. sorry for the fisrt my question is not clear. thanks . this is my code,i try.

    private DataTable dtSource = new DataTable();

    private int i = 0;

    protected void Page_Load(object sender, EventArgs e)

    {

    if (!IsPostBack)

    {

    loadData(1);

    RSFilm.SelectedDate = DateTime.Now;

    RadCalendar1.SelectedDate = RSFilm.SelectedDate;

    RadCalendar1.FocusedDate = RSFilm.SelectedDate;

    }

    else {

    loadData(Convert.ToInt32(SessionUtil.GetValueAsString("res_ID")));

    }

    }


    private void loadData(int ResourceID) {

    dtSource = RegistrationDB.GetWithStatusAndResource("A", ResourceID);

    RSFilm.DataSource = dtSource;

    RSFilm.DataStartField = "Registration_From";

    RSFilm.DataEndField = "Registration_To";

    RSFilm.DataKeyField = "Registration_ID";

    RSFilm.DataSubjectField = "Film_Title";

    RSFilm.DataBind();

    }

    protected void RSFilm_AppointmentCreated(object sender, AppointmentCreatedEventArgs e)

    {

    if(dtSource.Rows.Count >=0)

    {
    e.Appointment.BackColor=
    ColorTranslator.FromHtml(dtSource.Rows[0]["Film_UniqueColor"].ToString());
    i++;
    }

    }


  5. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 10 Oct 2007 Link to this post

    Hi Dao,

    Thank you for explaining in detail. This can be achieved using custom attributtes. Here is how:

    <telerik:RadScheduler ID="RadScheduler1" runat="server" CustomAttributeNames="Film_Color" ...> 

     protected void RadScheduler1_AppointmentDataBound(object sender, SchedulerEventArgs e)  
        {  
            e.Appointment.BackColor = e.Appointment.Attributes["Film_Color"];  
        } 

    Setting CustomAttributeNames="Film_Color" instructs RadScheduler to populate the custom attribute with values from the "Film_Color" column. You can access the value of the custom attribute in the AppointmentDataBound event.

    Feel free to contact us if you have any other questions.


    Greetings,
    Peter
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  6. datisgod
    datisgod avatar
    17 posts
    Member since:
    Mar 2007

    Posted 12 Oct 2007 Link to this post

      e.Appointment.BackColor = e.Appointment.Attributes["Film_Color"];  -> can't set back color for appointment. i must define many css class same as 
    .1Yellow
    {
    background-color:Yellow;
    }

    and in your css ex: Scheduler.Office2007.css , i deleted

    .RadScheduler_Office2007 .rsAptWrap

    {

    border-left: 1px solid #9FAA89;

    border-right: 1px solid #9FAA89;

    background:url(Scheduler/AppointmentBg.gif) repeat-x #BCD1A5;

    }



    in my code :
    e.Appointment.CssClass =
    "1" + e.Appointment.Attributes"Film_UniqueColor"].ToString();

    The appointment is changed color
    :)
     


        

  7. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 12 Oct 2007 Link to this post

    Hi Dao,

    Thanks for the feedback. Indeed, the BackColor property cannot be set to a string (this is what you get from the custom attribute). However, I got the impression from the code you sent earlier that you have a method which converts the string to the appropriate type for the BackColor property:

    e.Appointment.BackColor= ColorTranslator.FromHtml(dtSource.Rows[0]["Film_UniqueColor"].ToString());

    My assumption was that if I show you how to get a string value from the custom attribute you would be able to convert it to the appropriate type.

    Indeed, setting the CssClass property is an alternative solution.

    Feel free to contact us should you have any other questions.



    Best wishes,
    Peter
    the Telerik team

    Instantly find answers to your questions at the new Telerik Support Center
  8. Ranjan
    Ranjan avatar
    38 posts
    Member since:
    Sep 2011

    Posted 29 Sep 2011 Link to this post

    hi Peter,
    I have same problem in my case I am binding data to sql server in which all columns like startdate, enddate, subject and back color for each appointment is stored. What i have to do is showing appointments on that respective stored color stored in database column. How can i achieve this. thanks
  9. Stuart Hemming
    Stuart Hemming avatar
    1622 posts
    Member since:
    Jul 2004

    Posted 30 Sep 2011 Link to this post

    Ranjan.

    Have a look at this thread. In the small code sample I posted you can see a line like this ...

    e.Appointment.BackColor = ColorTranslator.FromHtml(calEvent.BackColour);

    This code is being executed in the AppointmentDataBound event handler. In the case above 'calEvent' is my data item which you can get at by casting e.Appointment.DataItem to the relevant type.

    -- 
    Stuart
    Don't forget to mark the question as answered.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017