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

Still Need Help Updating Records

4 Answers 10 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Perry
Top achievements
Rank 1
Perry asked on 08 Dec 2015, 08:13 PM

Am am using this example for my learning tool.  The example is using a SQL connection string for data access but I am using Data Entity so I am having to do some code translation.  So far I have been able to get the Parent RadGrid configured and can access the USerControl to display the record data when I click the edit link.  However Since I am very new to the RadGrid world and am still working on my C# skills I am having some difficulty with the code translation to perform the update.

In the Telerik example this code is used to start to process:

//Prepare new row to add it in the DataSource
       DataRow[] changedRows = this.Employees.Select("EmployeeID = " + editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["EmployeeID"]);

 This does not work for me  and I get this error message:

LinkAnalysis3.Subjects' does not contain a definition for 'Subjects' and no extension method 'Subjects' accepting a first argument of type 'LinkAnalysis3.Subjects' could be found (are you missing a using directive or an assembly reference?)

Okay I understand the error the Subjects table from the database is not identified, so I have no record or row selected.  So I tried this C# code:

DataRow[] changedRows = (results.Where(r => r.SubjectId = (editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["SubjectId"])));

 But it does not work and I get an error message stating :

"Cannot implicitly convert type 'object' to 'int'. An explicit conversion exists (are you missing a cast?)"

Can someone please explain what I am doing wrong and how I can get this fixed.

 

Thank You for your assistance.

Perry

 


 

 

4 Answers, 1 is accepted

Sort by
0
Perry
Top achievements
Rank 1
answered on 09 Dec 2015, 04:06 PM

Okay I have solved this problem by using the following code in the aspc.cs page to get the data I need from my selected Row.

GridEditableItem editedItem = e.Item as GridEditableItem;
            UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID);
           string subjectid = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["SubjectId"].ToString();
           int intSubject = Convert.ToInt16(subjectid);
           var results = from r in DbContext.Subjects.ToList()
                         where r.SubjectId == intSubject
                         select r;
           List<Subject> newSubject = results.ToList();
           //string test = newSubject[0].Comments;
            if (newSubject.Count != 1)
            {
 
                RadGrid1.Controls.Add(new LiteralControl("Unable to locate the Subject for updating."));
 
                e.Canceled = true;
 
                return;
 
            }
 So I can now get my row data but I had to change the update code to save my changes by modifying the code to this:

newSubject[0].FirstName = (userControl.FindControl("txtFirstName") as TextBox).Text;

These changes were made because I am not using a SQL connection.  I am using Data Entity.  The example also uses a HashTable which I did not need..

I am all most there BUT I have 2 drop downs lists on my form and now the code is not finding the control using this code: 

newSubject[0].Race = (userControl.FindControl("RadRaceDropDown") as DropDownList).SelectedItem.Text;

Would anyone be able to tell me why these controls are seen and how can I fix the problem?

 

 

0
Pavlina
Telerik team
answered on 11 Dec 2015, 04:51 PM
Hello,

I am not sure that I correctly understand what you are trying to achieve but if you want related dropdownlists in edit mode you can refer to the following code library:
http://www.telerik.com/support/code-library/using-cascading-radcomboboxes-into-the-radgrid-insert-edit-form

Regards,
Pavlina
Telerik
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 Feedback Portal and vote to affect the priority of the items
0
Perry
Top achievements
Rank 1
answered on 11 Dec 2015, 05:08 PM

You are correct my post did not do a good job of explaining what I was trying to accomplish.  I was trying to get the update/edit form I had created in the UserControl to perform the update.  The form would open and allow me to edit data but when I clicked the Update button I got the error  message I described.  I solved that problem with the changes I described in a later post.

The I added my second comment addressing the issue with the drop downs.  I have since corrected this by changing my code to match what you have in the demo.  In my code I tried to use a RadCombo box, which did not work.

Bottom line the application is now working.

 Thanks

 

 

0
Pavlina
Telerik team
answered on 12 Dec 2015, 12:42 PM
Hello,

At the end of your last post you are saying - Bottom line the application is now working. Does it mean that the problem is resolved and the case can be closed?

Regards,
Pavlina
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Perry
Top achievements
Rank 1
Answers by
Perry
Top achievements
Rank 1
Pavlina
Telerik team
Share this question
or