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

Edit/Update column in gridview(Silverlight + Sharepoint External List)

2 Answers 89 Views
GridView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Marcus
Top achievements
Rank 1
Marcus asked on 03 Aug 2012, 07:22 AM
Hey!

I would like to update / edit an external list in Sharepoint using Silverlight. Im using client object model, so I got a class with properties representing all the columns in the list.

I'm using the RowEditEnded event, to catch the current row that was edited.. Now I need to get the current row somehow from Sharepoint External List and update it.

My primary key is not called ID so I cannot use getItemByID. Ive tried using a caml query to achieve the same thing. But then i'm having problem retrieving just that one row?.

Any idea what to do? I gotta say it's rather strange to think that everyone uses "ID" as primary.

I know there is a way to do this in the Sharepoint Shell script like this: "$SPItem = $SPList.Items | Where { $_["CUSTOMER_ID"] -eq "Value of field you want to search for" }"

Ive enclosed my RowEdited function, with comments. If it is to any help

Appreciate some help, I am really stuck.

private void EditingRowsGrid_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
        {
            Sales editedRow = e.Row.DataContext as Sales; //Uses the class made representing all the columns.
 
            ClientContext editLoadData = new ClientContext(SPSite); //Open site
            List list = editLoadData.Web.Lists.GetByTitle(SPList); //Get by title SPList variable
            editLoadData.Load(list); //Load it
            CamlQuery query = new CamlQuery(); //initiate caml query
            query.ViewXml = "<View><Query><Where><Contains><FieldRef Name='CUSTOMER_ID'/><Value Type='Integer'>"    + editedRow.CUSTOMER_ID.ToString() + "</Value></Contains></Where></Query></View>";
            ListItemCollection items = list.GetItems(query); //Get the items using the caml query.
             
           //Here i am stuck, I am not sure that the above works either, but here I made a try accessing the one row, I fetched from             the list with items[0], didnt work. Any idea?
            ListItem oListItem = items[0];
 
            oListItem["test_column"] = editedRow.test_column.Trim();
            oListItem.Update();
            editLoadData.ExecuteQueryAsync(succeededCallbackUpdate, failedCallback);
        }

2 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 06 Aug 2012, 08:32 AM
Hi Marcus,

Based on the code-provided, I could only guess what might be causing the behavior you get. Nevertheless, could you clarify do you have a unique identifier for each item - why not calling GetItemByID(id) /the parameter is the value of the property that you use as unique identifier/ method ? Could you try to debug the application and verify whether at every step you get the expected items/item ? 
On a side note, I would recommend you to run through this or this articles that might be helpful as well.

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Marcus
Top achievements
Rank 1
answered on 06 Aug 2012, 08:44 AM
I got it working, the problem with getItemByID is that it looks for an ID column, which external lists doesn't have unless you create an ID column in the database table.

I sorted this out by looping through my gridview items array and then use an IF-case to find the row that was selected.

foreach (var item in Items)
           {
               
               if (editedRow.CUSTOMER_ID == item.FieldValues["CUSTOMER_ID"].ToString())
               {
                   item["COLUMN_NAME"] = editedRow.COLUMN_NAME;
                   item.Update();
                   context.ExecuteQueryAsync(succeededCallbackUpdate, failedCallback);
                   break;
               }
 
           }
Tags
GridView
Asked by
Marcus
Top achievements
Rank 1
Answers by
Maya
Telerik team
Marcus
Top achievements
Rank 1
Share this question
or