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

Dynamic Resources

6 Answers 142 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
L
Top achievements
Rank 1
L asked on 04 Jan 2012, 08:43 AM
hi

My company has a high turnover rate of employees and given the code sample telerik provided it is not dynamic for my situation. How do i make it dynamic without changing anything at the aspx page whenever there is a change at the employee table? thanks

 <ResourceTypes>
         <telerik:ResourceType KeyField="ID" Name="User" TextField="UserName" ForeignKeyField="UserID"
                        DataSourceID="UsersDataSource" />
  </ResourceTypes>
                <ResourceStyles>
                    <telerik:ResourceStyleMapping Type="User" Text="Alex" ApplyCssClass="rsCategoryBlue" />
                    <telerik:ResourceStyleMapping Type="User" Text="Bob" ApplyCssClass="rsCategoryOrange" />
                    <telerik:ResourceStyleMapping Type="User" Text="Charlie" ApplyCssClass="rsCategoryGreen" />
                </ResourceStyles>

6 Answers, 1 is accepted

Sort by
0
Accepted
Ivana
Telerik team
answered on 06 Jan 2012, 07:12 AM
Hi,

If you want to change the style of the appointments for which different users are selected, you could use the following code:
protected void Page_Load(object sender, EventArgs e)
{
    foreach (Resource res in RadScheduler1.Resources.GetResourcesByType("User"))
    {
        ResourceStyleMapping resMapping = new ResourceStyleMapping();
        resMapping.Key = res.Key.ToString();
        resMapping.BackColor = System.Drawing.Color.FromArgb(100, 100, 200);
 
        RadScheduler1.ResourceStyles.Add(resMapping);
    }
}
You could create a random integer generator which will create integers in a range from 0 to 255, so for different user you will have different color for the appointment.

<telerik:RadScheduler ID="RadScheduler1" runat="server" AppointmentStyleMode="Default" >
</telerik:RadScheduler>
The AppointmentStyleMode property set to Default will preserve the rounded corners of the appointments after applying the style.

All the best,
Ivana
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
0
Ryan Baxter
Top achievements
Rank 1
answered on 16 Nov 2012, 03:36 PM
I'm trying to implement this example but its not working for me on the initial page load, it works if the scheduler has an item edited/inserted/deleted and performs another post back.  I also tried to do this on the page.init and that didnt work either.  Ideas?

Imports Telerik.Web.UI
Imports System.Drawing
Imports System.Random
 
Public Class VacationCalendar
    Inherits System.Web.UI.Page
 
    Private m_Rnd As New Random
 
    Public Function RandomRGBColor() As Color
        Return Color.FromArgb(255, _
            m_Rnd.Next(0, 255), _
            m_Rnd.Next(0, 255), _
            m_Rnd.Next(0, 255))
    End Function
 
    Protected Sub Page_Load(sender As Object, e As EventArgs) Handles Me.Load
        ResourceStyles()
    End Sub
 
    Protected Sub ResourceStyles()
        For Each res As Resource In RadScheduler1.Resources.GetResourcesByType("Area")
            Dim resMapping As New ResourceStyleMapping()
            resMapping.Key = res.Key.ToString()
            resMapping.BackColor = RandomRGBColor()
 
            RadScheduler1.ResourceStyles.Add(resMapping)
        Next
    End Sub
End Class
0
Plamen
Telerik team
answered on 21 Nov 2012, 03:05 PM
Hi Ryan,

 
Such behavior may be observed if the resources are not loaded initially and the event does not get into your ForEach loop. 

Hope this 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.
0
Ryan Baxter
Top achievements
Rank 1
answered on 27 Nov 2012, 02:42 PM
I added a textbox to the loop and set the text to test at the end of the function/loop and the text is being set so I know its getting thru the function/loop the problem appears to be the scheduler isn't refreshing.  Like I said once I add a new event the colors then appear.  How do I force a refresh/redraw of the scheduler?  I tried a .Rebind() and that didn't do anything.
0
Boyan Dimitrov
Telerik team
answered on 30 Nov 2012, 01:26 PM
Hello,

Please find attached a sample project based on your code. A possible reason for this unusual behavior would be that your resource type name in the markup does not match the one used in the code behind.

//markup

<ResourceTypes>
            <telerik:ResourceType DataSourceID="SqlDataSource2" ForeignKeyField="UserID"
                KeyField="ID" Name="User" TextField="UserName" />
</ResourceTypes>

//code behind
Protected Sub ResourceStyles()
        For Each res As Resource In RadScheduler1.Resources.GetResourcesByType("User")
......
        Next
End Sub

Hope that this will be helpful.

Regards,
Boyan Dimitrov
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.
0
Ryan Baxter
Top achievements
Rank 1
answered on 30 Nov 2012, 07:41 PM
I ended up just applying it to the RadScheduler1.AppointmentDataBound
Tags
Scheduler
Asked by
L
Top achievements
Rank 1
Answers by
Ivana
Telerik team
Ryan Baxter
Top achievements
Rank 1
Plamen
Telerik team
Boyan Dimitrov
Telerik team
Share this question
or