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

set backcolor for Appointment

7 Answers 273 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
datisgod
Top achievements
Rank 1
datisgod asked on 08 Oct 2007, 09:25 AM

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

7 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 08 Oct 2007, 04:24 PM
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
0
datisgod
Top achievements
Rank 1
answered on 09 Oct 2007, 01:28 AM
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++;
}

}


0
Peter
Telerik team
answered on 10 Oct 2007, 09:28 AM
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
0
datisgod
Top achievements
Rank 1
answered on 12 Oct 2007, 06:50 AM

  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
:)
 


    

0
Peter
Telerik team
answered on 12 Oct 2007, 09:43 AM
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
0
Ranjan
Top achievements
Rank 1
answered on 29 Sep 2011, 06:47 PM
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
0
Stuart Hemming
Top achievements
Rank 2
answered on 30 Sep 2011, 08:12 AM
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.
Tags
Scheduler
Asked by
datisgod
Top achievements
Rank 1
Answers by
Peter
Telerik team
datisgod
Top achievements
Rank 1
Ranjan
Top achievements
Rank 1
Stuart Hemming
Top achievements
Rank 2
Share this question
or