asp.net asynchronous fetch DataTable and display implementation method _ Practical Tips

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.