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

Set Resource Styles dynamically

4 Answers 173 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 13 May 2009, 07:10 PM
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?

4 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 14 May 2009, 03:51 PM
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.
0
Matt
Top achievements
Rank 1
answered on 14 May 2009, 04:23 PM
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?
0
Accepted
Peter
Telerik team
answered on 16 May 2009, 02:22 PM
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.
0
Matt
Top achievements
Rank 1
answered on 18 May 2009, 05:59 PM
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 

Tags
Scheduler
Asked by
Matt
Top achievements
Rank 1
Answers by
Peter
Telerik team
Matt
Top achievements
Rank 1
Share this question
or