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

Cannot Edit Cell on Databound Grid

1 Answer 199 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Jassfer
Top achievements
Rank 1
Jassfer asked on 24 Mar 2016, 02:48 PM

Hi,

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

below is my Linq .

var voters = (
               from voter in db.VotersLists
                     .OrderBy(c => c.Barangay)
               from data in db.VotersDatas
                   .Where(b => b.RecId == voter.ID)
                   .DefaultIfEmpty()
               from leader in db.VotersLists
                   .Where(d => d.ID == data.LeaderID)
                   .DefaultIfEmpty()
               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";
     
or
       
     if (this.dg2.CurrentRow is GridViewRowInfo)
     {
         GridViewRowInfo editRow = dg2.CurrentRow;
         editRow.Cells["LeaderName"].Value = "TEST";
      }

 

 

1 Answer, 1 is accepted

Sort by
0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Mar 2016, 09:32 AM
Hello ,

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.
 
Regards,
Dess
Telerik
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Tags
GridView
Asked by
Jassfer
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Share this question
or