Cannot Edit Cell on Databound Grid

2 posts, 1 answers
  1. Jassfer
    Jassfer avatar
    1 posts
    Member since:
    Mar 2016

    Posted 24 Mar 2016 Link to this post


    I'm still new to Telerik and i'm having a hard time editing specific cell in the grid when user selected the row. 

    below is my Linq datasource.

    var voters = (
                   from voter in db.VotersLists
                         .OrderBy(c => c.Barangay)
                   from data in db.VotersDatas
                       .Where(b => b.RecId == voter.ID)
                   from leader in db.VotersLists
                       .Where(d => d.ID == data.LeaderID)
                   select new
                       ID = voter.ID,
                       VotersID = voter.VotersID,
                       Precinct = voter.Precinct,
                       Name = voter.Name,
                       Birthday = voter.Birthday.GetValueOrDefault().ToShortDateString(),
                       Sex = voter.Sex,
                       Barangay = voter.Barangay,
                       Address = voter.Address,
                       PoliticalParty = data.PoliticalParty,
                       IsRD = data.IsRD,
                       LeaderName = leader.Name,
                       LeaderPosition = data.LeaderPosition
                       ,DataID = data.ID.ToString() == null ? "" : data.ID.ToString()
                  dg2.DataSource = voters;

    I tried using the code below and it won't work.

         dg2.Rows[dg2.CurrentRow.Index].Cells[10].Value = "Test";
         if (this.dg2.CurrentRow is GridViewRowInfo)
             GridViewRowInfo editRow = dg2.CurrentRow;
             editRow.Cells["LeaderName"].Value = "TEST";



  2. Answer
    Dess avatar
    2110 posts

    Posted 25 Mar 2016 Link to this post

    Hello Jassfer,

    Thank you for writing.

    Such a query will return a list of anonymous objects. The objects in that list are read-only and that is why you cannot edit them in the grid. In this case, you have two options:
    1. Change the value in the data source manually when it is changed in the grid, execute the query again and rebind the grid. 
    2. Use RadVirtualGrid, this can save you the rebinding operation, but you will have to add some code to populate the grid. Detailed information about this is available here: Populating with Data.

    I hope this information is useful.
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top