转载

Ext.Net 1.x_Ext.Net.GridPanel如何后台遍历GridPanel中的数据?

A:

参见

  1. http://examples.ext.net/#/GridPanel/Selection_Models/Submitting_Values/
  2. http://examples.ext.net/#/GridPanel/Selection_Models/Row_Selection/

要点,前台提取数据,后台解析JSON字符串。

前台:

<Buttons> 
            <ext:Button runat="server" Text="Submit selection"> 
                <DirectEvents> 
                    <Click OnEvent="SubmitSelection"> 
                        <ExtraParams> 
                            <ext:Parameter Name="Values" Value="Ext.encode(#{GridPanel1}.getRowsValues({selectedOnly : true}))" Mode="Raw" /> 
                        </ExtraParams> 
                    </Click> 
                </DirectEvents> 
            </ext:Button> 
        </Buttons>

后台:

protected void SubmitSelection(object sender, DirectEventArgs e) 
{ 
    string json = e.ExtraParams["Values"]; 
      
    if (string.IsNullOrEmpty(json)) 
    { 
        return; 
    } 
      
    //XML will be represent as 
    //<records> 
    //   <record><Name>Alcoa Inc</Name><Price>29.01</Price><Change>0.42</Change><PctChange>1.47</PctChange></record> 
    //        ...   
    //   <record>...</record> 
    //</records> 
    XmlNode xml = JSON.DeserializeXmlNode("{records:{record:" + json + "}}"); 
  
    foreach (XmlNode row in xml.SelectNodes("records/record")) 
    { 
        string name = row.SelectSingleNode("Name").InnerXml; 
        string price = row.SelectSingleNode("Price").InnerXml; 
        string change = row.SelectSingleNode("Change").InnerXml; 
        string pctChange = row.SelectSingleNode("PctChange").InnerXml; 
          
        //handle values 
    } 
      
    List<Company> companies = JSON.Deserialize<List<Company>>(json); 
  
    foreach (Company company in companies) 
    { 
        string name = company.Name; 
        double price = company.Price; 
        double change = company.Change; 
        double pctChange = company.PctChange; 
  
        //handle values 
    } 
      
    Dictionary<string, string>[] companies1 = JSON.Deserialize<Dictionary<string, string>[]>(json); 
  
    foreach (Dictionary<string, string> row in companies1) 
    { 
        string name = row["Name"]; 
        string price = row["Price"]; 
        string change = row["Change"]; 
        string pctChange = row["PctChange"]; 
  
        //handle values 
    } 
      this.ResourceManager1.AddScript("Ext.Msg.alert('Submitted', 'Please see source code how to handle submitted data');"); 

}

文章最后发布于: 2012-09-14 13:22:36
展开阅读全文
0 个人打赏
私信求帮助

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 鲸 设计师: meimeiellie

分享到微信朋友圈

×

扫一扫,手机浏览