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

Autosave after edited a cell

2 Answers 230 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Øystein
Top achievements
Rank 1
Øystein asked on 27 May 2009, 01:28 PM
First of all I am sorry if this has been answered before, but I could not find anything about it.

I have a grid that binds it data to a Datatable and after load I put the whole column I want to be editable in edit mode.
This let the user edit data and automatically move to next row.

Is there a way to trigger automatic save after each edit?

I have tried using OnBlur event to trigger an AjaxRequest, but the problem is to get the ID of that row. Tried storing the ID in the ID of the textbox, but after updating the first Item the edittextbox lost that information.

I also looked into using OnTextChanged serverside event (I would prefer to get this to work), but it lost focus and did not move to next row.

Regards

Øystein


2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 28 May 2009, 06:36 AM
Hello Øystein,

You can refer to this online demo which demonstrates a similar scenario. In the example, on clicking a row the previously edited row is updated using the code below:
js:
 function RowClick(sender, eventArgs) 
         { 
             if(editedRow && hasChanges) 
             { 
                    hasChanges = false
                    if(confirm("Update changes?")) 
                 { 
 
                     $find("<%= RadGrid1.MasterTableView.ClientID %>").updateItem(editedRow); 
                 } 
             } 
         } 
You can use the same logic in the onblur event of the row or TextBox and see if it helps

Thanks
Princy.
0
Øystein
Top achievements
Rank 1
answered on 28 May 2009, 11:04 AM
Hi Princy.

Thanks for the reply. I have now added the ItemBound event and added onFocusIn and onFocusOut events to the edit textbox.

However I am not able to get the updated value. I also tried using the RadGrid_ItemUpdated event, but with no luck.

js:
function updateRow(editedRow) { 
 if (hasChanges) { 
  var am = $find("<%= RadAjaxManager1.ClientID %>"); 
                     
  am.ajaxRequest("Update_" + editedRow + "_"); 
  hasChanges = false;                     
 } 

c#:
protected void RagGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
  if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
  { 
    GridEditableItem item = (GridEditableItem)e.Item; 
    DataRowView row = (DataRowView)item.DataItem; 
 
    item.Attributes.Add("onFocusOut""updateRow('" + item.ItemIndex + "');"); 
    item.Attributes.Add("onFocusIn""getImage('" + row.Row[0] + "');"); 
 
    TextBox txt = (TextBox)item["Verdi"].Controls[0]; 
    txt.Width = Unit.Percentage(100); 
    txt.Style["border"] = "0px"
    txt.Style["font-family"] = "Segoe UI"
    txt.Style["font-size"] = "8pt"
  } 

Tags
Grid
Asked by
Øystein
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Øystein
Top achievements
Rank 1
Share this question
or