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

3 posts, 0 answers
  1. Marcus
    Marcus avatar
    5 posts
    Member since:
    Aug 2012

    Posted 03 Aug 2012 Link to this post

    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. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 06 Aug 2012 Link to this post

    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.

  3. Marcus
    Marcus avatar
    5 posts
    Member since:
    Aug 2012

    Posted 06 Aug 2012 Link to this post

    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;
                   }
     
               }
Back to Top