Too lazy to play other words, go directly to the subject bar
1. First, the data sheet rex_test
Id
|
Int
|
Self-increment
|
Tname
|
varchar (10)
|
Name
|
Temail
|
varchar (80)
|
Mailbox
|
2. As for the Jqurey Easyui package in the code, go directly to the official website to download it. Of course, other places are OK, there is no more explanation.
3. Foreground Display page
Default.aspx
<span style= "FONT-SIZE:14PX;" >
4. HANDLER3.ASHX (initial binding)
<span style= "FONT-SIZE:14PX;" ><%@ WebHandler language= "C #" class= "Handler3"%>using system;using system.web;using system.data;using System.data.sqlclient;using system.text;using System.io;public class Handler3:ihttphandler {public void ProcessReque St (HttpContext context) {Query (context); The public void Query (HttpContext context) {//calls the B-layer method to get the dataset sqlhelp Sqla = new Sqlhelp (); String Strfaca = "SELECT * from Rex_test"; DataSet ds = Sqla. GetDataSet (Strfaca); Convert the dataset to datable DataTable dt = ds. Tables[0]; int count = dt. Rows.Count; String Strjson = Dataset2json (ds, count);//dataset data into JSON data context. Response.Write (Strjson);//Return to the foreground page context. Response.End (); }///<summary>///DataSet converted to JSON format///</summary>//<paramname= "DS" >dataset</param& Gt <returns></returns> public static string Dataset2Json (DataSet ds, int total =-1) {StringBuilder json = new StringBuilder (); foreach (DataTable dt in DS. Tables) {//{"total": 5, "Rows": [JSON. Append ("{\" total\ ":"); if (total = =-1) {JSON. Append (dt. Rows.Count); } else {json. Append (total); } JSON. Append (", \" rows\ ": ["); Json. Append (Datatable2json (DT)); Json. Append ("]}"); } return JSON. ToString (); }///<summary>//DataTable converted to JSON format///</summary>//<paramname= "DT" ></param> <returns></returns> public static string Datatable2json (DataTable dt) {StringBuilder JSO NBuilder = new StringBuilder (); for (int i = 0; i < dt. Rows.Count; i++) {jsonbuilder.append ("{"); for (int j = 0; j < dt. Columns.count; J + +) {JSOnbuilder.append ("\" "); Jsonbuilder.append (dt. COLUMNS[J]. ColumnName); Jsonbuilder.append ("\": \ ""); Jsonbuilder.append (dt. ROWS[I][J]. ToString ()); Jsonbuilder.append ("\", "); } if (dt. Columns.count > 0) {jsonbuilder.remove (jsonbuilder.length-1, 1); } jsonbuilder.append ("},"); } if (dt. Rows.Count > 0) {jsonbuilder.remove (jsonbuilder.length-1, 1); } return jsonbuilder.tostring (); } public bool IsReusable {get {return false; }}}</span>
5.ADD.ASHX (new data)
<span style= "FONT-SIZE:14PX;" ><%@ WebHandler language= "C #" class= "Add"%>using system;using system.web;public Class add:ihttphandler { public void ProcessRequest (HttpContext context) { context. Response.ContentType = "Text/plain"; string result = String. Empty; String name = Context. request.querystring["name"]; string email = context. request.querystring["email"]; Sqlhelp Sqla = new Sqlhelp (); String sqlString = "INSERT into Rex_test (tname,temail) VALUES ('" +name+ "', '" +email+ "')"; BOOL AA = Sqla. ExecuteNonQuery (sqlString); Sqla. SQLClose (); if (aa) { result = "Join record succeeded"; } Context. Response.Write (result); } public bool IsReusable { get { return false; }}} </span>
6.DEL.ASHX (delete data)
<span style= "FONT-SIZE:14PX;" ><%@ WebHandler language= "C #" class= "del"%>using system;using system.web;public Class del:ihttphandler { public void ProcessRequest (HttpContext context) { context. Response.ContentType = "Text/plain"; string result = String. Empty; String id = context. request.querystring["id"]; Sqlhelp Sqla = new Sqlhelp (); String sqlString = "Delete from rex_test where id= '" + ID + "'"; BOOL AA = Sqla. ExecuteNonQuery (sqlString); Sqla. SQLClose (); if (aa) { result = "Delete succeeded"; } Context. Response.Write (result); } public bool IsReusable { get { return false; }}} </span>
7.REFRESH.ASHX (update data)
<span style= "FONT-SIZE:14PX;" ><%@ WebHandler language= "C #" class= "Refresh"%>using system;using system.web;public Class Refresh: IHttpHandler {public void ProcessRequest (HttpContext context) {context. Response.ContentType = "Text/plain"; string result = String. Empty; String id = context. request.querystring["id"]; String name = Context. request.querystring["Name"]; string email = context. request.querystring["email"]; Sqlhelp Sqla = new Sqlhelp (); String sqlString = "Update rex_test set tname= '" +name+ "', temail= '" +email+ "' where id= '" + ID + "'"; BOOL AA = Sqla. ExecuteNonQuery (sqlString); Sqla. SQLClose (); if (aa) {result = "update succeeded"; } context. Response.Write (Result); } public bool IsReusable {get {return false; }}}</span>
8. Basically, this looks almost the same. Even more refined things before you can do, the next time you have to send it.
Oh. By the way, the code of SQLHELP Sqla = new Sqlhelp (); In fact, it is a SQL operation class, write their own, there are a lot of such sqlhelper on the Internet. I'm not going to stick it out.
"Jqurey easyui+asp.net"----DataGrid data binding, and add, delete, change (SQL)