Drag and Drop from rad grid with non-ienumerable data

3 posts, 0 answers
  1. Justin
    Justin avatar
    20 posts
    Member since:
    Jul 2011

    Posted 04 Jun 2014 Link to this post

    Hi,

    Let me first start by saying I like your controls and products. I am implementing a RadGrid and Scheduler with the idea of dragging and dropping rows from the grid and placing them on the scheduler. I am using the following demo as a guideline: 
    http://demos.telerik.com/aspnet-ajax/scheduler/examples/draganddropintegration/defaultcs.aspx?product=scheduler

    The issue I am having is that in your example you are filling the rad grid with task data whose data table has an ID column with an int data type. When you drop the row over the grid it appears to use that integer ID field as the appointment id and places a new appointment in the index.

    Like this: 
    protected void RadGrid1_RowDrop(object sender, GridDragDropEventArgs e)
            {
                GridDataItem dataItem = e.DraggedItems[0];
     
                Hashtable values = new Hashtable();
                dataItem.ExtractValues(values);
                (int)dataItem.GetDataKeyValue("ID");
                string firstName = (string)values["FirstName"];
                string lastName = (string)values["LastName"];
                string targetSlotIndex = TargetSlotHiddenField.Value;
     
                if (targetSlotIndex != string.Empty)
                {
                    HandleSchedulerDrop(id, firstName, targetSlotIndex);
                    TargetSlotHiddenField.Value = string.Empty;
                }
                RadScheduler1.Rebind();
                rgGridViewUsers.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));
            }
     
     private void ScheduleAppointment(int id, string subject, DateTime start, DateTime end)
            {
                IDataSource dataSource = SchedulerDataSource;
                DataSourceView view = dataSource.GetView("DefaultView");
     
                IOrderedDictionary data = new OrderedDictionary();
                data.Add("Subject", subject);
                data.Add("Start", start);
                data.Add("End", end);
     
                IDictionary keys = new OrderedDictionary();
                keys.Add("ID", id);
                //keys.Add("ID", 234);
     
                view.Update(keys, data, new OrderedDictionary(), OnDataSourceOperationComplete);
            }
     
            private static bool OnDataSourceOperationComplete(int count, Exception e)
            {
                if (e != null)
                {
                    throw e;
                }
                return true;
            }


    However I am trying to add a list of users to the list where the ID column is unique identifier (Guid). After I dropping the even on the scheduler everything seems to work fine up until I get to the the callback OnDataSourceOperationComplete(), where i get an error stating that the key must be of the ienumerbale type.

    Here is my code again with the int datatype changed to Guid:
    protected void RadGrid1_RowDrop(object sender, GridDragDropEventArgs e)
           {
               GridDataItem dataItem = e.DraggedItems[0];
     
               Hashtable values = new Hashtable();
               dataItem.ExtractValues(values);
                
               Guid id = new Guid((string)values["ID"]);//(int)dataItem.GetDataKeyValue("ID");
               string firstName = (string)values["FirstName"];
               string lastName = (string)values["LastName"];
               string targetSlotIndex = TargetSlotHiddenField.Value;
     
               if (targetSlotIndex != string.Empty)
               {
                   HandleSchedulerDrop(id, firstName, targetSlotIndex);
                   TargetSlotHiddenField.Value = string.Empty;
               }
               RadScheduler1.Rebind();
               rgGridViewUsers.Rebind();
                
               RadAjaxManager1.AjaxSettings.AddAjaxSetting(RadGrid1, RadScheduler1);
           }
     
     
           private void HandleSchedulerDrop(Guid 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));
           }
     
     
    private void ScheduleAppointment(Guid id, string subject, DateTime start, DateTime end)
           {
               IDataSource dataSource = SchedulerDataSource;
               DataSourceView view = dataSource.GetView("DefaultView");
     
               IOrderedDictionary data = new OrderedDictionary();
               data.Add("Subject", subject);
               data.Add("Start", start);
               data.Add("End", end);
     
               IDictionary keys = new OrderedDictionary();
               keys.Add("ID", id);
               //keys.Add("ID", 234);
     
               view.Update(keys, data, new OrderedDictionary(), OnDataSourceOperationComplete);
           }
     
           private static bool OnDataSourceOperationComplete(int count, Exception e)
           {
               if (e != null)
               {
                   throw e;
               }
               return true;
           }

    Unfortunately I am not sure how to overcome this.

    Can you provide an example perhaps of how to drag and drop items that have a non integer ID column data type? Or if this is even possible?

    Thanks,
    -Justin
  2. Justin
    Justin avatar
    20 posts
    Member since:
    Jul 2011

    Posted 04 Jun 2014 Link to this post

    I convertible not Ienumerable sorry about that one.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Boyan Dimitrov
    Admin
    Boyan Dimitrov avatar
    1746 posts

    Posted 09 Jun 2014 Link to this post

    Hello,

    Please find here how you can use GUID for an appointment id value instead of int value. In this case in the RadGrid RowDrop you can simply create an appointment object and add it to the appointment collection.


    Regards,
    Boyan Dimitrov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top