This paper describes the implementation method of ASP.net to obtain a DataTable and display it asynchronously. Share to everyone for your reference, specific as follows:
The above is the result, the foreground code is as follows:
<%@ Page language= "C #" autoeventwireup= "true" codefile= "MethodOne.aspx.cs" inherits= "_default"%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
The
Process page program is as follows:
<%@ WebHandler language= "C #" class= "Handler"%> using System;
Using System.Web;
Using System.Data;
Using System.Data.SqlClient;
Using System.Text; public class Handler:ihttphandler {public void ProcessRequest (HttpContext context) {context.
Response.ContentType = "Text/plain"; if (context. request.querystring["Flag"]. Equals ("Data")) {context. Response.Write (GetResult (5,int32.parse) (context.
request.querystring["index"])); } if (context. request.querystring["Flag"]. Equals ("Count")) {context.
Response.Write (GetCount ());
} private String GetResult () {DataTable dt = new DataTable ();
using (SqlConnection conn = new SqlConnection (system.configuration.configurationmanager.appsettings["Conn"])) { Conn.
Open ();
String sql = "SELECT * from Testblog";
SqlDataAdapter SDA = new SqlDataAdapter (SQL, conn); Sda.
Fill (DT); int rlen = dt.
Rows.Count; int cLen = dt.
Columns.count; StringBuilder SB = new StringBuilder (); for (int j = 0; J < Rlen; J + +) {sb.
Append ("<tr>"); for (int i = 0; i < CLen i++) {sb.
Append ("<td>"); Sb. Append (dt. Rows[j][i].
ToString ()); Sb.
Append ("</td>"); } sb.
Append ("</tr>"); Return SB.
ToString ();
} private string GetResult (int pagecount,int currentpage) {datatable dt = new DataTable ();
using (SqlConnection conn = new SqlConnection (system.configuration.configurationmanager.appsettings["Conn"])) { Conn.
Open (); String sql = ' Select top ' +pagecount+ ' * from Testblog TB WHERE ydid ' not in ' (select Top +pagecount* (currentpage-1) + "Ydid
From Testblog tb2) ";
SqlDataAdapter SDA = new SqlDataAdapter (Sql,conn); Sda.
Fill (DT); int rlen = dt.
Rows.Count; int cLen = dt.
Columns.count;
StringBuilder sb = new StringBuilder (); for (int j = 0; J < Rlen; J + +) {sb.
Append ("<tr id=add" +j+ ">"); for (int i = 0; i < CLen i++) {sb.
Append ("<td>"); Sb. Append (dt. Rows[j][i].
ToString ()); Sb.
Append ("</td>"); } sb.
Append ("</tr>"); Return SB.
ToString ();
private String GetCount () {DataTable dt = new DataTable ();
using (SqlConnection conn = new SqlConnection (system.configuration.configurationmanager.appsettings["Conn"])) { Conn.
Open ();
String sql = "SELECT COUNT (*) from Testblog";
SqlDataAdapter SDA = new SqlDataAdapter (SQL, conn); Sda.
Fill (DT); } return DT. Rows[0][0].
ToString ();
public bool IsReusable {get {return false;
}
}
}
Unfortunately, the results are not shown in the IE7, but they are normal in Chrome, Firefox and Opera, and interested friends can improve on this.
I hope this article will help you to ASP.net program design.