Editing cell of GRID Sharepoint Telerik grid- Getting Value of a certain cell RowEditEnded

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

    Posted 01 Aug 2012 Link to this post

    Hey there!

    I m a little bit stuck here, I am working on a Silverlight Telerik gridview that is later to be uploaded into a SharePoint 2010 web part.
    Ive got 2 questions that has been bothering me that i would appreciate if anyone could answer.

    Im working on a gridview as mentioned and I do like to add a edit column functionality, fine that should be fairly easy ( I thought)

    I thought of using client object model (cus not REST nor any webservice is working within Silverlight and SharePoint along with external lists?)

    So I created a class that will represent the SharePoint list, with all the columns represented. Then I use the ClientContext retrieve the SharePoint list from site, All good.

    Now to the actual problem
    When it comes to editing since I need to push back the data to the SharePoint list, I need to alter the list somehow.

    So I used the function  private void EditingRowsGrid_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)

    Question: So now I need to get the the current row and get the ID from the unique column. How could that be accomplished?

    Ive tried with getting the data from the sharepoint list and pushing it in to my SalesItem class, that holds all the rows for the gridview.
    and then use    
    Sales test = e.OldValues as Sales; to get access to the current row that was edited and use test.CUSTOMER_CODE to get the unique column

    Heres my code:
     private void EditingRowsGrid_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
            {
                Sales test = e.OldValues as Sales;

                ClientContext context = new ClientContext(SPSite);
                List list = context.Web.Lists.GetByTitle(SPList);
                
                CamlQuery query = new CamlQuery();
                query.ViewXml = "<View><Query><Where><Contains><FieldRef Name='CUSTOMER_CODE'/><Value Type='Integer'>" + test.CUSTOMER_CODE + "</Value></Contains></Where></Query></View>";
                ListItemCollection items = list.GetItems(query);
                context.Load(items);
                context.ExecuteQuery();

    // Here goes the code to set the data that was changed/
            // then context.ExecuteAsync to push back the changed to the SharePoint list.
    }

    I think this should work, appearently it doesnt,that doesn't require me to create a class that holds the row item.
     
    Question: Is there a better way to edit and update the SharePoint List? 
     


    Please bear with the wall of text, I just wanted you to understand the idea. 
    Thanks in advance fore any help!
  2. Nedyalko Nikolov
    Admin
    Nedyalko Nikolov avatar
    871 posts

    Posted 01 Aug 2012 Link to this post

    Hi,

    Generally you can use "e.Row.DataContext" (within RowEditEnded event handler) to get the underlying data object (updated object) and push it to the SharePoint server (service). I believe that ID of the item is not editable information, so you could count on this fact. I would recommend using data properties instead of any visual objects (like cells or rows), because due to UI virtualization some visual object may not be created at all.

    Regards,
    Nedyalko Nikolov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

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

    Posted 01 Aug 2012 Link to this post

    Thanks. Got me a little bit on the road again. I am yet trying to figure out how to set the value back to the Sharepoint list.

    This is my function:
            private void EditingRowsGrid_RowEditEnded(object sender, GridViewRowEditEndedEventArgs e)
            {
                Sales editedRow = e.Row.DataContext as Sales; // As you said I got the current row and manage to find
       //the ID. Now I just need to find a way to push it back. First finding the row in the Sharepoint list. then writing back to the DB.


                ClientContext context = new ClientContext(SPSite);
                List list = context.Web.Lists.GetByTitle(SPList);
                CamlQuery query = new CamlQuery();
                query.ViewXml = "<View><Query><Where><Contains><FieldRef Name='CUSTOMER_CODE'/><Value Type='Integer'>" +     editedRow.CUSTOMER_CODE.ToString() + "</Value></Contains></Where></Query></View>";

    ListItemCollection items = list.GetItems(query);  
                list.Update();


    Loading the site with the camlquery... I am using the camlquery since i cannot use GetItemById from the clientContext since my unique name(primary key) is not called ID its "CUSTOMER_CODE". So I made my own with camlquery.
    I wanna find a way to turn the only ROW I got from camlquery, to an item, kinda like the editedRow variable. Is it possible?

    So that the items variable is acting the same as editedrow.
    Then I could just easily do the updates by accessing 

    items.CUSTOMER_NAME = editedRow.CUSTOMER_NAME; and then just do commit, to update.

    Any idea how I can accomplish this? I am starting to get lost :)

    Thanks in advance!


                
  4. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 06 Aug 2012 Link to this post

    Hi Marcus,

    I have just replied to the other thread you started. Please take a look at it and let me know in case you need further assistance. 

    Greetings,
    Maya
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top