1、前台页面
在button中添加ExtraParams
<DirectEvents> <Click> <ExtraParams> <ext:Prameter Name="Values" Value="Ext.encode({#GridPanelName}.getRowsValues({selectedOnly:true}))" Mode="Raw"> </ExtraParams> </Click> </DirectEvents>
Tips:(1)Ext.encode() 将对象转换成Json字符串;Ext.decode() 将Json字符串转换成对象
2、后台代码
string json=e.ExtraParams["Values"]; //得到json格式的数据 Dictionary<string, string>[] detail = JSON.Deserialize<Dictionary<string, string>[]>(json); //反序列化json成字典 foreach(Dictionary<string, string> row in sqlDetail ) { string id=row["ID"];..... 获取数据 }
Tips:JSON序列化与反序列化
(1)字典 Dictionary
//序列化 Dictionary<string, string> dic = new Dictionary<string, string>(); dic.Add("Name", "张三"); dic.Add("Age", "15"); dic.Add("Gender", "女"); string json = JSON.Serialize(dic); //反序列化 string json= @"[{"Name":"张三","Age":18,"Gender":"女"}]"; Dictionary<string, string> dic = JSON.Deserialize<Dictionary<string, string>>(json);
(2)集合 List
//序列化 List<Person> list = new List<Person>(); list.Add(new Person{Name="张三",Age=18,Gerder="女"}); list.Add(new Person{Name="李四",Age=21,Gender="男"}); string json = JSON.Serialize(list); //反序列化 string json=@"[{"Name":"张三","Age":18,"Gender":"女"},{"Name":"李四","Age":21,"Gender":"男"}]"; List<Person> list= JSON.Deserialize<List<Person>>(json);