Set Resource Styles dynamically

5 posts, 1 answers
  1. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2009

    Posted 13 May 2009 Link to this post

    Has anyone found a way to assign the resource styles in a database table and then call them through code?  I have two identical calendars(User and Admin) and thought it's redundant to hard code resource styles in both calendars.

    Here's an initial attempt i tried so far.  I figured if this worked then I could code a loop to read this info from a db.  But it didn't work.

    RadScheduler1.ResourceStyles.Clear() 
    RadScheduler1.ResourceStyles.Add(New Telerik.Web.UI.ResourceStyleMapping("EventType""Class""rsCategoryDarkBlue")) 

    Oh, and that's in the Page_Load event.  It successfully cleared all the styles, but didn't replace with the new syle assignment.  Where/when would I need to call this?  Or is there another way to do this altogether?
  2. Peter
    Admin
    Peter avatar
    6637 posts

    Posted 14 May 2009 Link to this post

    Hello Matt,

    Please, see this topic for reference:
    http://www.telerik.com/help/aspnet-ajax/appearance-setting-appointment-style.html

    Let us know if you need further help with this.

    All the best,
    Peter
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2009

    Posted 14 May 2009 Link to this post

    So is there any way to use RadScheduler1.ResourceStyles.Add()?

    If I used a db call in the ApptDataBound event to find the CssClass it would hit the db for every single appt, wouldn't it?  That would seemingly cause a lot of db overhead.  With my limited Telerik knowledge it seems like using the ResourceStyles.Add would just have to hit the db once.  Am I missing something?
  5. Answer
    Peter
    Admin
    Peter avatar
    6637 posts

    Posted 16 May 2009 Link to this post

    Hi Matt,

    There shouldn't be a problem setting resource styles dynamically. Here is what I tried and it worked fine:

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

    protected void Page_Load(object sender, EventArgs e)  
        {     
                RadScheduler1.ResourceStyles.Clear();  
                RadScheduler1.ResourceStyles.Add(new ResourceStyleMapping("User""1""rsCategoryDarkBlue"));  
                RadScheduler1.ResourceStyles.Add(new ResourceStyleMapping("User""2""rsCategoryDarkRed"));  
             
        } 

    If you continue to experience problems, please open a support ticket and send us a working demo which we can test locally.


    Sincerely yours,
    Peter
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Matt
    Matt avatar
    66 posts
    Member since:
    Apr 2009

    Posted 18 May 2009 Link to this post

    Ah, so I was setting the key incorrectly.

    Here's what I did to make it work with a db
           'Set Event Type Resource Style 
            oCmd.CommandText = "SELECT * FROM Table_ResourceStyles" 
            oCmd.CommandType = CommandType.Text 
            oCmd.Connection = oConn 
            oConn.Open() 
     
            oRdr = oCmd.ExecuteReader(CommandBehavior.CloseConnection) 
            If oRdr.HasRows Then 
                RadScheduler1.ResourceStyles.Clear() 
                Do While oRdr.Read 
                    RadScheduler1.ResourceStyles.Add(New ResourceStyleMapping("EventType", oRdr.Item("TableID"), oRdr.Item("CssClass"))) 
                Loop 
            End If 

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017