NET one sentence to take care of pagination

Source: Internet
Author: User

Rows is the number of rows sent by the client, page is the page number, the argument needs to be two parameters on the line, the SQL statement _row and _page self-declared local variables, the value or the corresponding row and page, in order to operate.

Use the database class to get its DataTable, converted to JSON format through the general processing program to the client, the client display is OK. Here I am using the Easyui DataGrid for receiving and transmitting 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 ORDER BY TestID Desc) Order BY testid Desc ";

//datatable converted to JSON, here with "Total", the number of data passed to the client, do not pass this, the client will not show the total data is how many bars.
Public Static stringCreatejsonparameters (DataTable DT,BOOLDisplaycount,inttotalcount) {StringBuilder jsonstring=NewStringBuilder (); //Exception Handling if(dt! =NULL) {jsonstring.append ("{ "); if(Displaycount) {jsonstring.append ("\ "Total\":"); Jsonstring.append (TotalCount); Jsonstring.append (","); } jsonstring.append ("\ "Rows\": ["); for(inti =0; i < dt. Rows.Count; i++) {jsonstring.append ("{ "); for(intj =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 ("}"); returnJsonstring.tostring (). Replace ("\ n",""); } Else { return NULL; } }

NET one sentence to take care of pagination

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.