A word easy to handle asp.net pagination _ practical Tips

Source: Internet
Author: User

Rows is the number of rows sent by the client, page is the page number, the argument requires two parameters on the line, SQL statements _row and _page their own declared local variables, the value or the corresponding row and page, in order to calculate just.

Use the database class to get its DataTable, convert the JSON format to the client via a generic handler, and the client displays OK. Here I use the Easyui DataGrid for receiving and passing parameters. This is the general idea.

String sql = ' Select top ' + Rows + ' * from TestData where TestID not in (select Top + (_rows * (_page-1)) + "TestID From TestData-TestID desc) Order BY testid Desc ";

The DataTable is converted to JSON, where the total is taken, the number of data passed to the client is not transmitted, and the client does not show how many items the total data is. public static string Createjsonparameters (DataTable DT, bool displaycount, int totalcount) {StringBuilder jsons
      Tring = new StringBuilder ();
        Exception handling if (dt!= null) {Jsonstring.append ("{");
          if (displaycount) {jsonstring.append ("\" total\ ":");
          Jsonstring.append (TotalCount);
        Jsonstring.append (",");
        } jsonstring.append ("\" rows\ ": ["); for (int i = 0; i < dt. Rows.Count;
          i++) {jsonstring.append ("{"); for (int j = 0; j < dt.) Columns.count; J + +) {if (J < dt. columns.count-1) {//if (dt.
              ROWS[I][J] = = DBNull.Value) continue; if (dt. COLUMNS[J]. DataType = = typeof (bool)) {jsonstring.append ("\" + dt. COLUMNS[J]. ColumnName + "\": "+ dt." ROWS[I][J]. TostrinG ().
              ToLower () + ","); else if (dt. COLUMNS[J]. DataType = = typeof (String)) {jsonstring.append ("\" + dt. COLUMNS[J]. ColumnName + "\": "+" \ "" + dt. ROWS[I][J]. ToString ().
              Replace ("\" "," \\\ ") +" \ ","); else {jsonstring.append ("\" + dt.) COLUMNS[J]. ColumnName + "\": "+" \ "" + dt.
              ROWS[I][J] + "\", "); ' Else if ' (j = = dt. columns.count-1) {//if (dt.
              ROWS[I][J] = = DBNull.Value) continue; if (dt. COLUMNS[J]. DataType = = typeof (bool)) {jsonstring.append ("\" + dt. COLUMNS[J]. ColumnName + "\": "+ dt." ROWS[I][J].
              ToString ()); else if (dt. COLUMNS[J]. DataType = = typeof (String)) {jsonstring.append ("\" + dt. COLUMNS[J].
                       ColumnName + "\": "+" \ "" +  Dt. ROWS[I][J]. ToString ().
              Replace ("\" "," \\\ ") +" ""); else {jsonstring.append ("\" + dt.) COLUMNS[J]. Columnname+ "\": "+" \ "+ dt.
              ROWS[I][J] + "" ""); }}/*end of string*/if (i = = dt.
          rows.count-1) {jsonstring.append ("}");
          else {jsonstring.append ("},");
        } jsonstring.append ("]");
        Jsonstring.append ("}"); Return jsonstring.tostring ().
      Replace ("\ n", "");
      else {return null;

 }
    }

The above is the entire content of this article, I hope to help you learn.

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.