Analysis of example methods for building paging application in C #

Source: Internet
Author: User
This article mainly introduces the method of building paging application in C #, and analyzes the concrete steps and related implementation techniques of C # to create paging function with instance form, and the friends who need can refer to the following

The example in this article describes how C # constructs a paging application. Share to everyone for your reference, as follows:

1. SQL statements

With [Temptableforstockic] as (  SELECT *,row_number () over (ORDER by Createtime DESC) as RowNumber from [Stockic] wher E 1=1 and Model = ' fty765op ') SELECT * from [Temptableforstockic] WHERE RowNumber between 1 and 10

2. Backstage method

<summary>///table name///</summary>private const string _tablenane = "Stockic";///<summary>///Get inventory list// /</summary>public list<stockicresult> getstockiclist (stockicparam param) {list<stockicresult>  List = new list<stockicresult> ();  String sql = "with [temptablefor{0}] as";  SQL + = "(select *,row_number () over (ORDER by {1}) as RowNumber from [{0}] WHERE 1=1 {2})";  SQL + = "SELECT * FROM [temptablefor{0}] WHERE RowNumber between {3} and {4}";  StringBuilder sqlcondition = new StringBuilder ();  list<sqlparameter> sqlparams = new list<sqlparameter> (); Model if (! String.IsNullOrEmpty (param. Model) {Sqlcondition.appendformat ("and model like '%{0}% '", Param.  Model); }//Start time if (param.    Begintime.hasvalue) {sqlcondition.append ("and Createtime >= @BeginTime"); Sqlparams.add (New SqlParameter ("@BeginTime", Param.  Begintime.value)); }//End time if (param. Endtime.hasvalue) {sqlcondition.append ("and Createtime < @ENdtime "); Sqlparams.add (New SqlParameter ("@EndTime", Param.  EndTime.Value.AddDays (1))); }//Sort if (String.isnullorwhitespace (param). ) {param.  = "Createtime DESC"; }//Paging param. PageIndex = param.  PageIndex-1; Int64 startnumber = param. PageIndex * param.  PageSize + 1; Int64 endnumber = Startnumber + param.  PageSize-1; Assemble SQL sql = String.Format (sql, _tablenane, param.  Sqlcondition, Startnumber, Endnumber); Execute SQL statement DataSet DataSet = Dbhelper.getreader (SQL.  ToString (), Sqlparams.toarray ());  List = Trantolist (DataSet); return list;}

Note: Dbhelper.getreader () method, Trantolist () method, etc. please improve yourself.

Some calculation methods

Paging Int64 Startnumber = (param. PageIndex-1) * param. PageSize + 1;int64 endnumber = Startnumber + param. pagesize-1;//Total Pages = (total data + paging size-1)/Paging size Totalpage = (totalcount + PageSize-1)/PageSize;
Related Article

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.