Problem description: The editorgridpanel of extjs can be modified and saved at one time in batches.
1. Save. js ---------------------------------------
VaR JSON = ""; // input the background JSON string
VaR flag = false; // whether to add a comma flag
VaR grid = new Ext. Grid. editorgridpanel ({
Clickstoedit: 1,
Listeners :{
Afteredit: function (e ){
If (FLAG ){
JSON + = ',';
}
Flag = true;
JSON + = '{"mid":' + '"' + E. Record. Data. m_id
+ '"," Ecode ":' + '"' + E. Value + '"}';
}
}
});
});
// JSON = "[{\" mid \ ": \" 3 \ ", \" ecode \ ": \" 2900.66 \ "},{ \" mid \": \ "4 \", \ "ecode \" :\" 2348.52 \ "}]";
Function savelotinfotodb () // click 'save' to transfer data to the savadata. ASPX page.
{
Ext. Ajax. Request ({
URL: '/savedata. aspx ',
Params :{
JSON: JSON
}, // Parameters uploaded to the background
Success: function (R, O ){
Ext. msg. Alert ('hprompt ',' modified successfully! ');
},
Failure: function (){
Ext. msg. Alert ("prompt", "failed to save! ");
}
});
}
2. savedata. aspx. CS ---------------------------------------
Protected void page_load (Object sender, eventargs E)
{
Save ();
}
/// <Summary> author: It Mongolian
/// Deserialize the JSON string into a net object
/// </Summary>
Public list <freedata> isefect (string JSON)
{
Memorystream stream2 = new memorystream ();
Datacontractjsonserializer ser2 = new datacontractjsonserializer (typeof (list <freedata> ));
Streamwriter wR = new streamwriter (stream2 );
Wr. Write (JSON );
Wr. Flush ();
Stream2.position = 0;
Object OBJ = ser2.readobject (stream2 );
List <freedata> List = (list <freedata>) OBJ;
Return list;
}
Public void save ()
{
String JSON = "[" + request ["JSON"] + "]";
String SQL = NULL;
List <freedata> ls = isefect (JSON );
For (INT I = 0; I <ls. Count; I ++)
{
Int id = ls [I]. Mid;
Float code = ls [I]. ecode); // SQL + = "Update userinfo set salary =" + code + "where id =" + ID + ";";
}
// Return sqlecute (SQL); // execute the database update statement to save (multiple) data records.
}
---------------------------------------------------------------
Note: Pay attention to the freedata class here. The property name in the freedata class must be prefixed with the key name of the JSON data with "_", so that the LS [I] in the SAVE () function will be added. mid, ls [I]. the ecode gets the correct value (this is not very positive, but I cannot get the value when I first wrote the attribute name to another one ).
3. freedata. CS ---------------------------------------
Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. Web;
/// <Summary> author: It Mongolian
/// Freedata Summary
/// </Summary>
Public class freedata
{
Private int _ mid;
Private float _ ecode;
Public freedata ()
{}
Public float ecode
{
Get {return _ ecode ;}
Set {This. _ ecode = value ;}
}
Public int mid {
Get {return _ mid ;}
Set {_ mid = value ;}
}
}
========================================================== ========================================================== ==========
As a result, the strings passed by extjs (containing multiple pieces of data) are converted into C # objects and the values are obtained.
Comments from readers!
Author: It Mongols
Source: http://hi.baidu.com/qing_bd_liang/item/537cf93751e063ca2e8ec28b