bootstrap-table-editable 小结

先贴一个json类

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Script.Serialization;
using System.Data;
namespace PH.Common
{
    ///  
    /// JSON帮助类 
    ///  
    public class JSONHelper
    {
        ///  
        /// 对象转JSON 
        ///  
        /// 对象 
        /// JSON格式的字符串 
        public static string ObjectToJSON(object obj)
        {
            JavaScriptSerializer jss = new JavaScriptSerializer();
            try
            {
                return jss.Serialize(obj);
            }
            catch (Exception ex)
            {
                throw new Exception("JSONHelper.ObjectToJSON(): " + ex.Message);
            }
        }
        ///  
        /// 数据表转键值对集合 
        /// 把DataTable转成 List集合, 存每一行 
        /// 集合中放的是键值对字典,存每一列 
        ///  
        /// 数据表 
        /// 哈希表数组 
        public static List> DataTableToList(DataTable dt)
        {
            List> list
            = new List>();
            foreach (DataRow dr in dt.Rows)
            {
                Dictionary dic = new Dictionary();
                foreach (DataColumn dc in dt.Columns)
                {
                    dic.Add(dc.ColumnName, dr[dc.ColumnName]);
                }
                list.Add(dic);
            }
            return list;
        }
        ///  
        /// 数据集转键值对数组字典 
        ///  
        /// 数据集 
        /// 键值对数组字典 
        public static Dictionary>> DataSetToDic(DataSet ds)
        {
            Dictionary>> result = new Dictionary>>();
            foreach (DataTable dt in ds.Tables)
                result.Add(dt.TableName, DataTableToList(dt));
            return result;
        }
        ///  
        /// 数据表转JSON 
        ///  
        /// 数据表 
        /// JSON字符串 
        public static string DataTableToJSON(DataTable dt)
        {
            return ObjectToJSON(DataTableToList(dt));
        }
        ///  
        /// JSON文本转对象,泛型方法 
        ///  
        /// 类型 
        /// JSON文本 
        /// 指定类型的对象 
        public static T JSONToObject(string jsonText)
        {
            JavaScriptSerializer jss = new JavaScriptSerializer();
            try
            {
                return jss.Deserialize(jsonText);
            }
            catch (Exception ex)
            {
                throw new Exception("JSONHelper.JSONToObject(): " + ex.Message);
            }
        }
        ///  
        /// 将JSON文本转换为数据表数据 
        ///  
        /// JSON文本 
        /// 数据表字典 
        public static Dictionary>> TablesDataFromJSON(string jsonText)
        {
            return JSONToObject>>>(jsonText);
        }
        ///  
        /// 将JSON文本转换成数据行 
        ///  
        /// JSON文本 
        /// 数据行的字典 
        public static Dictionary DataRowFromJSON(string jsonText)
        {
            return JSONToObject>(jsonText);
        }
    }
}


后台webservice

实现规则就是先执行操作再返回操作后的object ,当然要用json处理下。

修改就是返回修改后的object  删除就是返回一个Id相同其它项是null的object

1、显示

 public void GetResourceList()
    {
        List list = new PH.BLL.Resource().GetModelList("1=1");
        string strJson = PH.Common.JSONHelper.ObjectToJSON(list);
        Context.Response.Write(strJson);
        Context.Response.End();
    }

2、修改

 public void ModifyResourceList()
    {
        HttpRequest request = HttpContext.Current.Request;
        PH.BLL.Resource pbr = new PH.BLL.Resource();
        PH.Model.Resource pmr = pbr.GetModel(int.Parse(request["Id"]));
        pmr.Content = request["Content"];
        pmr.Length = request["Length"];
        pmr.Link = request["Link"];
        pmr.Name = request["Name"];
        pmr.Title = request["Title"];
        pmr.Type = request["Type"];
        pmr.UnitId = request["UnitId"];
        pbr.Update(pmr);

        string strJson = PH.Common.JSONHelper.ObjectToJSON(pmr);
        Context.Response.Write(strJson);
        Context.Response.End();
    }

3、删除

public void RemoveResourceList()
    {
        HttpRequest request = HttpContext.Current.Request;
        PH.BLL.Resource pbr = new PH.BLL.Resource();
        pbr.Delete(int.Parse(request["Id"]));

        PH.Model.Resource pmr = new PH.Model.Resource();
        pmr.Id = int.Parse(request["Id"]);

        string strJson = PH.Common.JSONHelper.ObjectToJSON(pmr);
        Context.Response.Write(strJson);
        Context.Response.End();
    }


前端 导入css 和 js清单

 
 
 

 
 
 
 
 
 


前端html

  

前端js

 

查询  js+

 queryParams: function (params) {
        return {
            Id: $('#id').val(),
            pageSize: params.limit,
            offset: params.offset,
            sortOrder: params.order,
            UnitId: $('#unitid').val(),
            Name: $('#name').val()............................
        }
    },
    url: 'Webservice.asmx/QueryResourceList'
}

后台  还是用前面的方法取值

 HttpRequest request = HttpContext.Current.Request;
 request["*****"]



你可能感兴趣的:(前端)