Dynamic Resources

7 posts, 1 answers
  1. L
    L avatar
    298 posts
    Member since:
    Apr 2008

    Posted 04 Jan 2012 Link to this post

    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>
  2. Answer
    Ivana
    Admin
    Ivana avatar
    657 posts

    Posted 06 Jan 2012 Link to this post

    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
  3. Ryan Baxter
    Ryan Baxter avatar
    6 posts
    Member since:
    Feb 2004

    Posted 16 Nov 2012 Link to this post

    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
  4. Plamen
    Admin
    Plamen avatar
    2966 posts

    Posted 21 Nov 2012 Link to this post

    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.
  5. Ryan Baxter
    Ryan Baxter avatar
    6 posts
    Member since:
    Feb 2004

    Posted 27 Nov 2012 Link to this post

    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.
  6. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    2061 posts

    Posted 30 Nov 2012 Link to this post

    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.
  7. Ryan Baxter
    Ryan Baxter avatar
    6 posts
    Member since:
    Feb 2004

    Posted 30 Nov 2012 Link to this post

    I ended up just applying it to the RadScheduler1.AppointmentDataBound
Back to Top