重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
前台显示页面:grid.html
创新互联是一家专注于网站设计、成都网站建设与策划设计,井冈山网站建设哪家好?创新互联做网站,专注于网站建设十载,网设计领域的专业建站公司;建站业务涵盖:井冈山等地区。井冈山做网站价格咨询:028-86922220
public class grid : IHttpHandler { public void Proce***equest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request["action"].ToString(); switch (action) { case "query": Query(); break; case "del": Del(); break; case "add": Add(); break; case "edit": Edit(); break; } } ////// 查询并分页 /// private void Query() { string str = string.Empty; string rows = HttpContext.Current.Request["rows"].ToString(); //获取datagrid传来的行数 string page = HttpContext.Current.Request["page"].ToString(); //获取datagrid传来的页码 当前页 // GetTablebyproc上篇文章的调用带参数的存储过程,返回datat DataTable dt1 = SqlHelper.GetTablebyproc("pageFileter", int.Parse(rows), int.Parse(page), "stu"); DataTable dt = SqlHelper.GetTable("select * from stu"); str = JSonHelper.CreateJsonParameters(dt1, true, dt.Rows.Count); HttpContext.Current.Response.Write(str); } ////// 删除一行数据 /// private void Del() { string str = "删除失败"; string id = HttpContext.Current.Request["id"] != "" ? HttpContext.Current.Request["id"].ToString() : ""; if (id != string.Empty) { int num = SqlHelper.DelData("stu", id); if (num > 0) { str = string.Format("删除成功,本次共删除{0}条", num.ToString()); } else { str = "删除失败"; } } HttpContext.Current.Response.Write(str); } ////// 添加一条数据 /// private void Add() { StringBuilder sb = new StringBuilder(); foreach (string s in HttpContext.Current.Request.Form.AllKeys) { sb.AppendFormat("{0}: {1}\n", s, HttpContext.Current.Request.Form[s]); } string str = sb.ToString(); string[] str1 = str.Split('&'); string no = str1[1].Split('=')[1]; string name = str1[2].Split('=')[1]; string pwd = str1[3].Split('=')[1]; string sex = str1[4].Split('=')[1]=="1"?"男":"女"; int age = int.Parse(str1[5].Split('=')[1]); string add = str1[6].Split('=')[1]; string address = add.Substring(0, add.Length - 1); string sql = string.Format("insert into stu values('{0}','{1}','{2}','{3}',{4},'{5}')", no, name, pwd, sex, age, address); int count = 0; count = SqlHelper.ExeNonQuery(sql, CommandType.Text, null) ? 1 : 0; if (count > 0) { HttpContext.Current.Response.Write("ok"); } else { HttpContext.Current.Response.Write("no"); } } ////// 修改一条数据 /// private void Edit() { StringBuilder sb = new StringBuilder(); foreach (string s in HttpContext.Current.Request.Form.AllKeys) { sb.AppendFormat("{0}: {1}\n", s, HttpContext.Current.Request.Form[s]); } string str = sb.ToString(); string[] str1 = str.Split('&'); int id = int.Parse(str1[0].Split('=')[1]); string no = str1[1].Split('=')[1]; string name = str1[2].Split('=')[1]; string pwd = str1[3].Split('=')[1]; string sex = str1[4].Split('=')[1] == "1" ? "男" : "女"; int age = int.Parse(str1[5].Split('=')[1]); string add = str1[6].Split('=')[1]; string address = add.Substring(0, add.Length - 1); string sql = string.Format("update stu set no='{0}',name='{1}',pwd='{2}',sex='{3}',age={4},address='{5}' where id={6}", no, name, pwd, sex, age, address, id); int count = 0; count = SqlHelper.ExeNonQuery(sql, CommandType.Text, null) ? 1 : 0; if (count > 0) { HttpContext.Current.Response.Write("ok"); } else { HttpContext.Current.Response.Write("no"); } }