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

Resource index out of range: 1

4 Answers 111 Views
Scheduler
This is a migrated thread and some comments may be shown as answers.
Tom Graham
Top achievements
Rank 1
Tom Graham asked on 17 Mar 2010, 12:57 PM
I am using the Drag and Drop integration example. When I drag a row from the RadGrid onto the scheduler while the scheduler is group by resources I get the error "Resource index out of range: 1". This is the sample default.aspx.cs code I am trying to use. I have noted that when grouped by resources the slotTargetindex format goes from "1:0:0" to "0:1:0:0". Any help would be appreciated.

Thanks, Tom

protected void RadGrid1_RowDrop(object sender, GridDragDropEventArgs e)  
        {  
            GridDataItem dataItem = e.DraggedItems[0];  
 
            Hashtable values = new Hashtable();  
            dataItem.ExtractValues(values);  
 
            int id = (int) dataItem.GetDataKeyValue("AppointmentID");  
            string subject = (string) values["Subject"];  
            string targetSlotIndex = TargetSlotHiddenField.Value;  
 
            if (targetSlotIndex != string.Empty)  
            {  
                HandleSchedulerDrop(id, subject, targetSlotIndex);  
                TargetSlotHiddenField.Value = string.Empty;  
            }  
            RadScheduler1.Rebind();  
            RadGrid1.Rebind();  
            RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadGrid1, RadScheduler1);  
        }  
 
        private void HandleSchedulerDrop(int id, string subject, string targetSlotIndex)  
        {  
            RadScheduler1.Rebind();  
 
            ISchedulerTimeSlot slot = RadScheduler1.GetTimeSlotFromIndex(targetSlotIndex);  
 
            TimeSpan duration = TimeSpan.FromHours(1);  
            if (slot.Duration == TimeSpan.FromDays(1))  
            {  
                duration = slot.Duration;  
            }  
 
            ScheduleAppointment(id, subject, slot.Start, slot.Start.Add(duration), slot.Resource);  
        }  
 
 
        protected void RadScheduler1_AppointmentCommand(object sender, AppointmentCommandEventArgs e)  
        {  
            if (e.CommandName == "Unschedule")  
            {  
                int id = (int)e.Container.Appointment.ID;  
                  
                DateTime dueDate = DateTime.Now;  
                  
                if (!string.IsNullOrEmpty(e.Container.Appointment.Attributes["Due"]))  
                    dueDate = Convert.ToDateTime(e.Container.Appointment.Attributes["Due"]);  
                  
                string priority = "Medium";  
                  
                if (!string.IsNullOrEmpty(e.Container.Appointment.Attributes["Priority"]))  
                    priority = e.Container.Appointment.Attributes["Priority"];  
                  
                UnscheduleAppointment(id, dueDate, priority);  
                RadScheduler1.Rebind();  
                RadGrid1.Rebind();  
 
                RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadScheduler1, RadGrid1);  
            }  
        }  
 
        private void UnscheduleAppointment(int id, DateTime dueDate, string priority)  
        {  
            IDataSource dataSource = SqlDataSource2;  
            DataSourceView view = dataSource.GetView("DefaultView");  
 
            IOrderedDictionary data = new OrderedDictionary();  
            data.Add("Start", null);  
            data.Add("End", null);  
            data.Add("Due", dueDate);  
            data.Add("Priority", priority);  
             
            IDictionary keys = new OrderedDictionary();  
            keys.Add("AppointmentID", id);  
 
            view.Update(keys, data, new OrderedDictionary(), OnDataSourceOperationComplete);  
        }  
 
        private void ScheduleAppointment(int id, string subject, DateTime start, DateTime end, Resource res)  
        {  
            IDataSource dataSource = SqlDataSource1;  
            DataSourceView view = dataSource.GetView("DefaultView");  
 
            IOrderedDictionary data = new OrderedDictionary();  
            data.Add("Subject", subject);  
            data.Add("Start", start);  
            data.Add("End", end);  
            data.Add("employeeid", res);  
                          
 
            IDictionary keys = new OrderedDictionary();  
            keys.Add("AppointmentID", id);  
 
            view.Update(keys, data, new OrderedDictionary(), OnDataSourceOperationComplete);  
        }  
 
        private static bool OnDataSourceOperationComplete(int count, Exception e)  
        {  
            if (e != null)  
            {  
                throw e;  
            }  
            return true;  
        } 

4 Answers, 1 is accepted

Sort by
0
Peter
Telerik team
answered on 19 Mar 2010, 04:05 PM
Hi Tom,

Please, try without calling Rebind():

private void HandleSchedulerDrop(int id, string subject, string targetSlotIndex)   
        {   
            RadScheduler1.Rebind();   
   


All the best,
Peter
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Ashley
Top achievements
Rank 1
answered on 21 Jul 2010, 05:03 PM
This does keep the error from occurring, but prevents the RadScheduler from being updated via Rebind(). In my code, I am using a ASP.NET timer to periodically update the schedule from it's data source. Is there another way to achieve this?
0
Peter
Telerik team
answered on 27 Jul 2010, 09:48 AM
Hello Ashley,

Can you open a support ticket and send us a simple working demo of the issue?

Best wishes,
Peter
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Ashley
Top achievements
Rank 1
answered on 28 Jul 2010, 04:01 PM
I found a work-around. In my code, I had a RadGrid and a RadScheduler in my project, and were linked via AJAX. 

I changed my Timer to call a Rebind() on the RadGrid object instead of the RadScheduler one, thus achieved the same end result without the error.
Tags
Scheduler
Asked by
Tom Graham
Top achievements
Rank 1
Answers by
Peter
Telerik team
Ashley
Top achievements
Rank 1
Share this question
or