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

RadGrid - Linq editing with select new { }

1 Answer 172 Views
GridView
This is a migrated thread and some comments may be shown as answers.
mSchmidt
Top achievements
Rank 1
mSchmidt asked on 16 Sep 2008, 03:11 PM
Hi

I have a Grid bound as below, i am able to enter edit state on the TextBoxes however upon end edit the value entered is not persisted in the grid (meaning the datasource)

Why is this ?
If it is not possible to have a "select new { }" in the linq query and still edit, how should i then do this ?


            rounds.MasterGridViewTemplate.Columns.Clear();  
            rounds.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn("Hjemme", "tName") { Width = 120,ReadOnly=true });  
            rounds.MasterGridViewTemplate.Columns.Add(new GridViewTextBoxColumn("Bane", "lane_HomeNum") { Width = 55HeaderText = "Bane" });  
            rounds.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn("Ude", "tName2") { Width = 120ReadOnly = true });  
            rounds.MasterGridViewTemplate.Columns.Add(new GridViewTextBoxColumn("Bane Ude", "lane_awayNum") {  Width = 55HeaderText = "Bane"DataType = typeof(int) });  
            rounds.MasterGridViewTemplate.Columns.Add(new GridViewDataColumn("Anden dato", "round_id") { Width = 50ReadOnly = true });  
            rounds.MasterGridViewTemplate.AutoGenerateColumns = false;  
            var q = from v in db.match_dbs  
                    where v.round_id == roundID  
                    select new { v.match_id,  tName =  v.team_db.team_name,v.lane_HomeNum,  v.lane_awayNum , tName2 = v.team_db1.team_name };  
 
            rounds.DataSource = q

1 Answer, 1 is accepted

Sort by
0
Jordan
Telerik team
answered on 18 Sep 2008, 03:23 PM
Hello mSchmidt,

What you see is normal behavior (except of the grid that allows to enter edit mode) because as stated in the MSDN documentation "Anonymous types provide a convenient way to encapsulate a set of read-only properties into a single object". The important part here is read-only, meaning that you have bound RadGridView to a read-only view of your data and that is why the changes are not persisted.

If you want the changes to be persisted you will not have to use the select new { v.match_id,  tName =  v.team_db.team_name,v.lane_HomeNum,  v.lane_awayNum , tName2 = v.team_db1.team_name }
statement.

For example you could just try "select v", in which case you should have no problems.

Hope this helps. Do not hesitate to write if you have more questions.

Greetings,
Jordan
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
GridView
Asked by
mSchmidt
Top achievements
Rank 1
Answers by
Jordan
Telerik team
Share this question
or