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

How to get the resources combo box in advanceform to select the right index from code behind?

2 Answers 37 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Yoav
Top achievements
Rank 1
Yoav asked on 10 Nov 2012, 12:24 PM

I’m reevaluating your asp.net suit. First I must say it has improved a lot since last time and you seem to attend to all of my remarks back then.

Right now I’m testing the scheduler. I want to drag and drop from a grid, and open the insert form in the dropped place. Everything seems to work, except for the resources that seem to lose the selected information in the attributes fields.

I’ve being playing around with the demos and currently the code behind looks like this. The form is opened with the right subject and time, but the resources combos index are never selected:


protected void RadGrid1_RowDrop(object sender, GridDragDropEventArgs e)
        {
            GridDataItem dataItem = e.DraggedItems[0];
 
            Hashtable values = new Hashtable();
            dataItem.ExtractValues(values);
 
            Int64 patId = (Int64)dataItem.GetDataKeyValue("ID"); // patient ID from grid
            ViewState["PID"] = Convert.ToString(patId);
            string fnm = (string)values["fnm"];
            string lnm = (string)values["lnm"];
            string subject = "New appointment for " + fnm + ' ' + lnm;
            string targetSlotIndex = TargetSlotHiddenField.Value;
 
            if (targetSlotIndex != string.Empty)
            {
                RadScheduler1.Rebind();
                ISchedulerTimeSlot slot = RadScheduler1.GetTimeSlotFromIndex(targetSlotIndex);
 
                TimeSpan duration = TimeSpan.FromHours(1);
                if (slot.Duration == TimeSpan.FromDays(1))
                {
                    duration = slot.Duration;
                }
                 
                Appointment app = new Appointment();
                app.Start = slot.Start;
                app.End = slot.Start.Add(duration);
                app.Subject = subject;
                app.Attributes["PatientID"] = Convert.ToString(patId);
                app.Attributes["PhysicianID"] = "1";
                //RadScheduler1.InsertAppointment(app);
 
                TargetSlotHiddenField.Value = string.Empty;
                 
                RadScheduler1.Rebind();
 RadScheduler1.ShowAdvancedEditForm(app);
                RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadGrid1, RadScheduler1);
            }    
        }





2 Answers, 1 is accepted

Sort by
0
Yoav
Top achievements
Rank 1
answered on 11 Nov 2012, 01:03 PM
For some reason *all* of the code examples for the solution in the forum and knowledge base are incorrect. Was there an undocumented breaking change or am I missing something?

In any case, for all those who try to get/set a resource control in the advancedform, you can’t use the name part of the control as it is shown in the examples. The name changes and a ‘Res’ is added to it. Therefore “e.Container.FindControl("Room")” will always return null, because it should be e.Container.FindControl("ResRoom").


Or you can use something like this to get the control name: 

Control ResourceControlContainer = (Control)e.Container.FindControl("ResourceControls");
String id = ResourceControlContainer.Controls[0].Controls[0].Controls[1].ID;

So if you have this declaration:

<ResourceTypes>
 <telerik:ResourceType DataSourceID="DataSource1" ForeignKeyField="PID"
 KeyField="ID" Name="Rooms" TextField="nm" />
</ResourceTypes>

You should use this in the FormCreated event:

RadComboBox patCombo = (RadComboBox)e.Container.FindControl("ResRooms");


0
Boyan Dimitrov
Telerik team
answered on 14 Nov 2012, 11:41 AM
Hello Yoav,

Please find here some detailed information about accessing Resources and Custom Attributes in the RadScheduler AdvancedForm. This help article provides additional information about syntax specifications in order to access and use those objects.  

Hope that this information will be helpful.

Kind 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.
Tags
Scheduler
Asked by
Yoav
Top achievements
Rank 1
Answers by
Yoav
Top achievements
Rank 1
Boyan Dimitrov
Telerik team
Share this question
or