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

Retrieve the ID of a specific row

1 Answer 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rosco
Top achievements
Rank 1
Rosco asked on 30 May 2010, 02:17 AM
I am trying to implement drag and drop functionality for a single RadGrid. My RadGrid is bound as follows:

       private void RetrieveData() 
        { 
            ////first retrieve projects 
            List<UIProject> projects = RetrieveProjects(); 
 
            projects.ForEach(a => 
            { 
                a.Features = (from u in Helper.DataContextFromWeb.MagUserstories 
                              where u.MagProjectId == a.ProjectId && u.Statuscode == 1 
                              orderby u.MagTitle 
                              select new UIFeature 
                              { 
                                  FeatureId = u.MagUserstoryId, 
                                  FeatureName = u.MagTitle 
                              }).ToList(); 
 
                a.Features.ForEach(b => 
                { 
                    b.Tasks = (from t in Helper.DataContextFromWeb.MagTasks 
                               where t.MagUserStoryId == b.FeatureId && t.Statuscode == 1 
                               orderby t.MagTitle 
                               select new UITask 
                               { 
                                   TaskName = t.MagTitle, 
                                   ActualHours = t.MagActualTime, 
                                   EstimatedHours = t.MagEstimatedTime, 
                                   //Status =  
                                   //Owner =  
                               }).ToList(); 
                }); 
            }); 
 
            BindMasterBackLog(projects); 
        } 
 
        private void BindMasterBackLog(List<UIProject> projects) 
        { 
            this.masterbacklog.DataSource = projects; 
            this.masterbacklog.DataMember = MagProject.Fields.MagProjectId; 
            this.masterbacklog.DataBind(); 
        } 
Data is retrieved from Microsoft Dynamics CRM and displayed in the grid correctly. Now, I am trying to implement the server-side onRowDrop event handler. The line below is giving me an "Index was out of range. Must be non-negative and less than the size of the collection" error. Could this be due to the way that I have bound the RadGrid? Please help.

UIProject project = RetrieveProject(projects, (Guid)e.DestDataItem.GetDataKeyValue("ProjectId")); 



1 Answer, 1 is accepted

Sort by
0
Radoslav
Telerik team
answered on 03 Jun 2010, 09:20 AM
Hello Rosco,

The described error is thrown when the MasterTableView.DataKeyNames property is not set. Could you please verify that you set the MasterTableView.DataKeyNames to the "ProjectId"?
Also please check out the following online example which demonstrates the RadGrid's Items Drag-and-drop:
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/draganddrop/defaultcs.aspx

Additionally regarding you question about RadGrid data binding:

Simple data-binding can be used in simple cases when you do not require the grid to perform complex operations. For advanced features, RadGrid must be bound using declarative data sources or through the NeedDataSource event.

Best wishes,
Radoslav
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.
Tags
Grid
Asked by
Rosco
Top achievements
Rank 1
Answers by
Radoslav
Telerik team
Share this question
or