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

3 posts, 0 answers
  1. Yoav
    Yoav avatar
    4 posts
    Member since:
    Sep 2010

    Posted 10 Nov 2012 Link to this post

    I’m reevaluating your 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();
                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)
                    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";
                    TargetSlotHiddenField.Value = string.Empty;
                    RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadGrid1, RadScheduler1);

  2. Yoav
    Yoav avatar
    4 posts
    Member since:
    Sep 2010

    Posted 11 Nov 2012 Link to this post

    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:

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

    You should use this in the FormCreated event:

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

  3. Boyan Dimitrov
    Boyan Dimitrov avatar
    2035 posts

    Posted 14 Nov 2012 Link to this post

    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.
Back to Top