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

How to set Appointment.cssClass by Resource

8 Answers 130 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
briankb
Top achievements
Rank 2
briankb asked on 09 Nov 2008, 02:42 AM
I found your sample for setting the cssClass by Subject but I need to set it according to one of the resource ID's.

Here is the sample code from your documentation
Protected Sub RadScheduler1_AppointmentCreated(sender As Object, e As Telerik.Web.UI.AppointmentCreatedEventArgs)
   Select Case e.Appointment.Subject
      Case "McGregor"
         e.Appointment.CssClass = "McGregorStyle"
      Case "John Doe"
         e.Appointment.CssClass = "JDStyle"
      Case "Smith"
         e.Appointment.CssClass = "SmithStyle"
      Case "Anderson"
         e.Appointment.CssClass = "AndersonStyle"
      Case Else
   End Select
End Sub 'RadScheduler1_AppointmentCreated

My Appointment table schema is the standard demo table with the following added fields
Appointment
- AppointmentID
- Subject
- StartDate
- EndDate
- RecurrenceRule
- RecurrenceParentID
- LocationID
- RoomID
- GroupID

related tables
Location
- LocationID
- LocationName

Room
-
RoomID
-
RoomName

Group
-
GroupID
-
GroupName
- GroupColor

I need to set the e.Appointment.cssClass according to the GroupID field. I tried to figure it out but my OOP skills are considerably lacking.

Ideally I want to allow in our admin for the customer to set their own color, using the RadColorPicker, for each Group they create. Since it seems the related table data is also in the scheduler hierachy would it be possible to have it set the color automatically based on a new column Group.GroupColor field?

8 Answers, 1 is accepted

Sort by
0
Accepted
Peter
Telerik team
answered on 11 Nov 2008, 12:37 PM
Hi brian,

The help topic you refer to is outdated. Please, use the following approach:

aspx:
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title></title>  
    <style type="text/css">  
    .Red .rsAptOut  
    {  
        background: red !important;  
    }  
    .Blue .rsAptOut  
    {  
        background: blue !important;  
    }  
    .Green .rsAptOut  
    {  
        background: green !important;  
    }  
    </style> 
</head> 
<body> 
    <form id="form1" runat="server">  
    <asp:ScriptManager ID="ScriptManager1" runat="server">  
    </asp:ScriptManager> 
    <telerik:RadScheduler ID="RadScheduler1" 
      SelectedView="WeekView" 
        runat="server" DataEndField="End"    
        DataKeyField="ID"   
        DataRecurrenceField="RecurrenceRule"   
        DataRecurrenceParentKeyField="RecurrenceParentID"   
        DataSourceID="AccessDataSource1"   
        DataStartField="Start"   
        DataSubjectField="Subject" 
         HoursPanelTimeFormat="htt"   
        ValidationGroup="RadScheduler1" Height=""   
        onappointmentdatabound="RadScheduler1_AppointmentDataBound">  
        <ResourceTypes> 
            <telerik:ResourceType DataSourceID="AccessDataSource2" KeyField="ID"  ForeignKeyField="GroupID" 
                Name="Group" TextField="GroupName" /> 
        </ResourceTypes> 
    </telerik:RadScheduler>   
    <asp:AccessDataSource ID="AccessDataSource2" runat="server"   
        DataFile="~/App_Data/scheduler1.mdb" SelectCommand="SELECT * FROM [Group]">  
    </asp:AccessDataSource> 
    <asp:AccessDataSource ID="AccessDataSource1" runat="server"   
        DataFile="~/App_Data/scheduler1.mdb"   
        DeleteCommand="DELETE FROM [Appointments] WHERE [ID] = ?"   
        InsertCommand="INSERT INTO [Appointments] ([Subject], [Start], [End], [RecurrenceRule], [RecurrenceParentID], [RoomID], [ExpectedCompletionDate], [GroupID]) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"   
        SelectCommand="SELECT * FROM [Appointments]"   
        UpdateCommand="UPDATE [Appointments] SET [Subject] = ?, [Start] = ?, [End] = ?, [RecurrenceRule] = ?, [RecurrenceParentID] = ?, [RoomID] = ?, [ExpectedCompletionDate] = ?, [GroupID] = ? WHERE [ID] = ?">  
        <DeleteParameters> 
            <asp:Parameter Name="ID" Type="Int32" /> 
        </DeleteParameters> 
        <UpdateParameters> 
            <asp:Parameter Name="Subject" Type="String" /> 
            <asp:Parameter Name="Start" Type="DateTime" /> 
            <asp:Parameter Name="End" Type="DateTime" /> 
            <asp:Parameter Name="RecurrenceRule" Type="String" /> 
            <asp:Parameter Name="RecurrenceParentID" Type="Int32" /> 
            <asp:Parameter Name="RoomID" Type="Int32" /> 
            <asp:Parameter Name="ExpectedCompletionDate" Type="DateTime" /> 
            <asp:Parameter Name="GroupID" Type="Int32" /> 
            <asp:Parameter Name="ID" Type="Int32" /> 
        </UpdateParameters> 
        <InsertParameters> 
            <asp:Parameter Name="Subject" Type="String" /> 
            <asp:Parameter Name="Start" Type="DateTime" /> 
            <asp:Parameter Name="End" Type="DateTime" /> 
            <asp:Parameter Name="RecurrenceRule" Type="String" /> 
            <asp:Parameter Name="RecurrenceParentID" Type="Int32" /> 
            <asp:Parameter Name="RoomID" Type="Int32" /> 
            <asp:Parameter Name="ExpectedCompletionDate" Type="DateTime" /> 
            <asp:Parameter Name="GroupID" Type="Int32" /> 
        </InsertParameters> 
    </asp:AccessDataSource> 
    </form> 
</body> 
</html> 

code-behind:
 protected void RadScheduler1_AppointmentDataBound(object sender, Telerik.Web.UI.SchedulerEventArgs e)  
    {  
        if (e.Appointment.Resources.GetResourceByType("Group") != null)  
            e.Appointment.CssClass = DataBinder.Eval(e.Appointment.Resources.GetResourceByType("Group").DataItem, "GroupColor").ToString();  
    } 

Attached is a demo web site for reference.


Peter
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
briankb
Top achievements
Rank 2
answered on 11 Nov 2008, 12:48 PM
Thanks!!! Much easier than I expected.
0
Peter
Telerik team
answered on 11 Nov 2008, 01:17 PM

Yes. :) The new DataItem property for both appointment and resource objects we introduced for Q3 2008 makes this possible.




Peter
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rubihno
Top achievements
Rank 1
answered on 12 Nov 2008, 12:57 PM
Hi, for those that have an older version (RadControls Ajax 2008.1619), exist another possibility for make the same function?with another  system?

I have the same problem..

Resourcetype ("Classroom")

Table Classroom

ID_Classroom
Name
Color <----

Table Reservation

ID_Reservation
...
...
ID_Classroom



0
Peter
Telerik team
answered on 12 Nov 2008, 05:14 PM
Hello Rubihno,

Unfortunately, there isn't an easy way to do this for versions older than Q3 2008. Are there any reasons why you cannot use the current version?


Best wishes,
Peter
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rubihno
Top achievements
Rank 1
answered on 12 Nov 2008, 05:33 PM
I use a version RadConstrol Ajax 2008 Q2, e and is not possible implement this code:

 

Protected Sub RadScheduler1_AppointmentDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.SchedulerEventArgs) Handles RadSchedulerPrenotazioni.AppointmentDataBound

 

 

 

e.Appointment.CssClass = DataBinder.Eval(RadSchedulerPrenotazioni.Resources.GetResourceByType(

"Classroom"). ->??? DataItem

The dataitem property there isn't...

How i make to implement this using another method? 

 

0
Peter
Telerik team
answered on 14 Nov 2008, 12:53 PM
Hi Rubihno,

The DataItem property is available only as from the Q3 version. Therefore, you cannot use a third column in your resource data table to read the css name for the appointments.

However, you can use the resouce Text or Key properties to assign css classes based on it. For example,

 protected void RadScheduler1_AppointmentDataBound(object sender, Telerik.Web.UI.SchedulerEventArgs e)     
    {     
        if (e.Appointment.Resources.GetResourceByType("Group") != null)     
            e.Appointment.CssClass = e.Appointment.Resources.GetResourceByType("Group").Text;  
    }    
 

Suppose that you have three types for Group name - GroupA, GroupB and GroupC. Then you need the following
css styles:
 <style type="text/css">     
    .GroupA .rsAptOut     
    {     
        backgroundred !important;     
    }     
    .GroupB .rsAptOut     
    {     
        backgroundblue !important;     
    }     
    .GroupC .rsAptOut     
    {     
        backgroundgreen !important;     
    }     
    </style>    
 



All the best,
Peter
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Rubihno
Top achievements
Rank 1
answered on 14 Nov 2008, 02:17 PM
Thanks, but is not possible to use a classDataset, Datarow to read a third column Color and set the cssclass?
Tags
Scheduler
Asked by
briankb
Top achievements
Rank 2
Answers by
Peter
Telerik team
briankb
Top achievements
Rank 2
Rubihno
Top achievements
Rank 1
Share this question
or