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

[Solved] Set Resource Index in Code Behind

3 Answers 216 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 2
David asked on 02 Apr 2008, 11:19 PM
When editing an appointment in the Scheduler control, I'm trying to get the resource to show what I'm pulling from the database.  If I do this from the Design View it works fine.  However, I'm trying to dynamically show resources based on certain conditions, so I have to create them on the fly.

I already have the Resources set from our database being created, but the value from the resource doesn't match up with what's in the database.  For example, if the resource named "Letter" has values A, B, C and the value is B in the database, the resource will remain in the "Unselected" position.

Can you please tell me how to correctly set the value of the resource in the code behind file?

Thanks,
David

3 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 03 Apr 2008, 12:28 PM
Hello David,

Here is an example how to do this:
<ResourceTypes>    
            <telerik:ResourceType DataSourceID="SqlDataSource2" ForeignKeyField="RoomID"      
                KeyField="ID" Name="Rooms" TextField="RoomName" />    
        </ResourceTypes>   

protected void RadScheduler1_FormCreated(object sender, Telerik.Web.UI.SchedulerFormCreatedEventArgs e)     
    {     
        if (e.Container.Mode == Telerik.Web.UI.SchedulerFormMode.AdvancedEdit ||     
            e.Container.Mode == Telerik.Web.UI.SchedulerFormMode.AdvancedInsert)     
        {                 
            Control c1 = (Control)e.Container.FindControl("_advancedControlsPanel");     
            Control ResourceControlContainer = (Control)c1.FindControl("ResourceControls");     
            DropDownList resourceDropDown = (DropDownList)ResourceControlContainer.FindControl("Rooms");     
            resourceDropDown.SelectedValue = "this";    
        }     
    }   

Let us know if you have further questions.

Regards,
Peter
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
David
Top achievements
Rank 2
answered on 03 Apr 2008, 05:35 PM

OK.  I have implemented the code below and it works fine after the initial load.
However, when I run an update on the scheduler it doesn't reset the resource index like it did on the initial load.  It keeps saying that the Resource Count inside SchedulerFormCreatedEventArgs is 0.  I don't have any code inside the update process other than running a stored procedure.

Why does this happen?

Also, the ControlTargetID changes after the Update event is fired and my RadToolTipManager can't find the Resources anymore.  Why does this happen?

Thanks in advance,
David

protected void RadScheduler1_FormCreated(object sender, SchedulerFormCreatedEventArgs e)

{

if (e.Container.Mode == Telerik.Web.UI.SchedulerFormMode.AdvancedEdit ||

e.Container.Mode == Telerik.Web.UI.

SchedulerFormMode.AdvancedInsert)

{

//Setting of the Event Type Resource Index

if (e.Container.Appointment.Resources.GetResourceByType("Event Type") != null)

{ intEventTypeIndex = (

int)(e.Container.Appointment.Resources.GetResourceByType("Event Type").Key); }

Control c1 = (Control)e.Container.FindControl("_advancedControlsPanel");

Control ResourceControlContainer = (Control)c1.FindControl("ResourceControls");

DropDownList resourceDropDown = (DropDownList)ResourceControlContainer.FindControl("Event Type");

resourceDropDown.SelectedIndex = intEventTypeIndex;

//Setting of the Room Resource Index

if (e.Container.Appointment.Resources.GetResourceByType("Room") != null)

{ intRoomIndex = (

int)(e.Container.Appointment.Resources.GetResourceByType("Room").Key); }

Control c2 = (Control)e.Container.FindControl("_advancedControlsPanel");

Control ResourceControlContainer2 = (Control)c2.FindControl("ResourceControls");

DropDownList resourceDropDown2 = (DropDownList)ResourceControlContainer2.FindControl("Room");

resourceDropDown2.SelectedIndex = intRoomIndex;

}

}

0
Peter
Telerik team
answered on 04 Apr 2008, 01:51 PM
Hi David,

I am not sure what exactly you want to achieve, but I think the Binding To Generic List online example might provide you with some ideas. More specifically, consider this part of the code-behind:

private void InitializeResources()  
        {  
            ResourceType resType = new ResourceType("User");  
            resType.ForeignKeyField = "UserID";  
 
            RadScheduler1.ResourceTypes.Add(resType);  
            RadScheduler1.Resources.Add(new Resource("User", 1, "Alex"));  
            RadScheduler1.Resources.Add(new Resource("User", 2, "Bob"));  
            RadScheduler1.Resources.Add(new Resource("User", 3, "Charlie"));  
        }  
 

If this does not help, please give us more details or open a support ticket and send us a demo project.


Cheers,
Peter
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
Scheduler
Asked by
David
Top achievements
Rank 2
Answers by
Peter
Telerik team
David
Top achievements
Rank 2
Share this question
or