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

RadGrid vs EditMode vs accessing DataItem

1 Answer 81 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Przemek
Top achievements
Rank 1
Przemek asked on 31 Aug 2012, 08:01 AM
Dear Telerik,

I've got a RadGrid, which has been filled with data from EntityDataSource - perfect. First column contains a GridEditCommandColumn, which fires correctly and display a FormTemplate with plenty of TextBoxes, FormTemplate contains also w RadButton with CommandName="Update" (and Cancel) - data updating works perfecty.
One of bound columns is a "Status_ID" column, which is related to another table (MSSQL). Statuses are displayed (inside FormTemplate) with RadTreeView control - also works perfectly. Unfortunately I could not find any solution for "automagical" binding "SelectedValue" of RadTreeView control with some of "Bind(column)" expression, so I've used the "NodeDataBound" event and if node.Value equals my Status_ID I select it.

Unfortunately the problem is, when I'd like to change another node from RadTreeView and fire data updating. Now I'm using such method (just after NodeClick)

var n = (e.Node);
int selectedStatus = int.Parse(e.Node.Value.ToString());
if (Respondent_Current == null)
{
  int respondentId = int.Parse((this.RadGrid_Respondent.EditItems[0] as GridDataItem).GetDataKeyValue("ID").ToString());
  Respondent_Current = Csi_Entities.PB_Respondent.Where(i => i.ID.Equals(respondentId)).First();
}
if (Respondent_Current != null)
{
  Respondent_Current.Status_ID = selectedStatus;
  this.Csi_Entities.SaveChanges();
  this.RadGrid_Respondent.Rebind();
}
else { //Crap }


Which works, but it's ugly - when I update textboxes AND i update RadTreeView just after and I submit, the textboxes-changes are ignored where status is updated correctly - but it's obvious with my solution.

What would be nice:
1. When node click - update an entity object which is used by FormTemplate (not the new one).
- Maybe I should update data by accessing the (EditItems[0] as GridDataItem).DataItem as MyEntity)? Will it work?
2. On CommandName="Update" fired, all controls might be successfully updated - am I right?

Thank you for ur time & help ;)

All the best,
Przemek M. Zawada

1 Answer, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 05 Sep 2012, 01:52 PM
Hello Przemek,

1. Yes you can get the data item and update it manually if you like.

2. When update is fired only the controls from current edit form will be used to get the new data and update the record. You can update only 1 record at a time.

All the best,
Vasil
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Przemek
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Share this question
or