• Linq 结果转成 json


      public string BindGrid(string page,string rows)
            {
                int pageIndex = 0;
                if (pageIndex < 1)
                {
                    pageIndex = 1;
                }
                int pageSize = 20;
                int totalcount = 0;
                string out_s = "";

                using (SmtDataContext db = new SmtDataContext())
                {
                    using (var writer = File.AppendText(Log.getLogFile()))
                    {
                        db.Log = writer;
                        var loadOptions = new DataLoadOptions();
                        db.LoadOptions = loadOptions;
                        string orderby = "order_no";

                            var q_count = from c in db.tb_orders select c;
                          

                            totalcount = q_count.Count();
                            //Skip(100)代表跳过100行后.从第101行开始分页;
                            //take(10)表示多少行分页;
                            // 第一种                    var aClass = q_count.OrderBy(p => GetPropertyValue(p, orderBy.SelectedValue.Trim())).Skip((pageIndex - 1) * pageSize).Take(pageSize);
                            // 第2种
                            var aClass = LinqOrderBy.OrderByDescending(q_count, orderby).Skip((pageIndex - 1) * pageSize).Take(pageSize);
                            JavaScriptSerializer serializer = new JavaScriptSerializer();
                            string json = serializer.Serialize(aClass);
                        //easyui 格式        {  "total":239, "rows":[ {"code":"010","name":"Name 10"} ]}   
                             StringBuilder sb = new StringBuilder();
                             sb.Append("{ "total":" + totalcount + ", "rows":" + json + "}");
                             out_s = sb.ToString();
                            writer.Close();
                    }
                }
                return out_s;
            }

  • 相关阅读:
    Using X++ code Hided to Main Content Panel Frame
    Call a method on caller form
    Infolog in the Dynamics AX 2009
    Using X++ code Customizations to statusLine
    Using X++ Code force Synchronisation DataBase
    英语口语精选100句(转)
    OpenPrinter_1: rc:0 lastError:1801(0x709) The printer name is invalid
    30岁前不要去在乎的29件事(转)
    安全措施挡出黑客攻击
    接口的实便
  • 原文地址:https://www.cnblogs.com/xinyaoxp/p/3198204.html
Copyright © 2020-2023  润新知