关于C#前后台搭配使用BootGrid控件,调用数据库并返回值
来源:互联网 发布:淘宝妈妈装店铺推荐 编辑:程序博客网 时间:2024/06/04 00:53
本文主要围绕关于C#前后台搭配使用BootGrid控件,调用数据库并返回值。
HTML5代码
设置元素参数和内容,并指定元素ID
<div class="grid-body"> <table id="tbDocList" data-toggle="bootgrid"> <thead> <tr> <th data-column-id="DocID">ID</th> <th data-column-id="DocName">文件名</th> </tr> </thead> </table></div>
JS代码
页面中的ID与JS中ID匹配
$('#tbDocList').bootgrid({ selection: true, multiSelect: true, rowSelect: true, keepSelection: false, ajax: true, ajaxSettings: { method: 'GET', cache: false }, post: function () { return { action: 'GetDocList', ID: document.getElementById("ID").value }; }, url: '../../路径A/类B.ashx', rowSize: 10, rowCount: [10], labels: { all: "所有", //修改为空内容。 infos: "显示{{ctx.start}}-{{ctx.end}}条,共{{ctx.total}}条", loading: "载入中。。。", refresh: "刷新", noResults: "无记录!" }, responseHandler: function (response) { if (response.IsSuccess) { return response.Data; } else { alert(response.Message); return null; } }, });
———————————————————我是后台——————————————————
后台代码中“GetDocList”需要与前台bootgrid使用ajax传输过来的参数名称一致
public void ProcessRequest(HttpContext context) { string action = context.Request["action"].ToString(); bool result = false; i = 1; switch (action) { case "GetDocList": page =int.Parse(context.Request.QueryString["current"]); dt = GetDocList(context); break; default: context.Response.ContentType = "text/plain"; context.Response.Write("Hello World"); break; } context.Response.ContentType = "text/plain"; var list = dt.AsEnumerable(); var datas = list.Skip((page - 1) * 10) .Take(10) .Select(dr => new { NO = (page - 1) * 10 + i++, DocID = dr.Field<int>("DocID"), DocName = dr.Field<string>("DocName") }); var data = new { current = page, rowCount = 10, rows = datas, total = list.Count() }; context.Response.Write(AjaxResult.Success(data)); }
这里后台就会调用GetDocList方法
这里做了一个代码处理
private DataTable GetDocList(HttpContext context) { int flag = int.Parse(context.Request["flag"]); DataTable DocInfo = new DataTable(); DocInfo = Initial(context); return DocInfo; } public DataTable Initial(HttpContext context) { string ID = context.Request["DocName"].ToString(); DBAccess oDBA = new DBAccess(); SqlParameter[] param = new SqlParameter[1]; param[0] = new SqlParameter("@ID", SqlDbType.Int); param[0].Value = int.Parse(ID); //传入参数到存储过程,并返回table DataSet ds = new DataSet(); ds = oDBA.CallSP("USP_GetDocInfo", param); DataTable DocInfo = ds.Tables[0]; return DocInfo; }
oDBA.CallSP 这个调用存储过程的方法请参考“如何使用C#连接SQLServer”
0 0
- 关于C#前后台搭配使用BootGrid控件,调用数据库并返回值
- 请求,调用数据库, 前后台交互
- 前后台$.post交互并返回JSON对象
- Asp.net前后台值的调用
- Asp.net前后台值的调用
- 前后台代码调用
- ajax前后台调用
- 前后台相互调用
- 前后台相互调用
- C#前后台线程
- jsp登陆页面和前后台验证并连接数据库
- Jsp登陆页面和前后台验证并连接数据库
- c#中,前后台方法间的调用
- 在后台调用FormView控件并赋值
- json前后台使用
- 前后台互相调用Function
- demo.jsp 前后台调用
- c#浅谈前后台线程
- javabean的设计原则
- Android 7.0 ActivityManagerService(6) Service相关流程分析
- 《APP研发录》读记
- noip2013day1第三题 货车运输LCA+并查集
- 利用bootstrap实现悬浮窗口的效果
- 关于C#前后台搭配使用BootGrid控件,调用数据库并返回值
- Android中的动画,选择器,样式和主题的使用
- ROS机器人程序设计(原书第2版)补充资料 教学大纲
- org.hibernate.tuple.entity.PojoEntityTuplizer 错误解决办法
- IOS运行时
- 字符串匹配算法--BF算法(暴力破解法)+KMP算法
- msm8953-dtsi的编译
- 浅谈大型网站架构技术进化
- iOS蓝牙开发CoreBluetooth快速入门