Asp.net-Repeater usage

Source: Internet
Author: User

Retrieve paging data (multiple sorting fields) /// <summary> /// retrieve paging data (multiple sorting fields) /// </summary> /// <param name = "pageSize"> page size </param> /// <param name = "pageIndex"> current page index </ param> /// <param name = "recordCount"> Number of records </param> /// <param name = "where"> query condition </param> /// <returns> </returns> public DataTable GetListManyOrderFile (int pageIndex, int pageSize, string table, string orderField, int orderType, string where, string key, out int rec OrdCount) {if (where = null) where = ""; OpenConn (); SqlCommand cmd = new SqlCommand ("P_Page_ManyOrderFile", conn); cmd. commandType = CommandType. storedProcedure; cmd. parameters. add ("@ tblName", SqlDbType. varChar, 800); cmd. parameters ["@ tblName"]. value = table; cmd. parameters. add ("@ fldName", SqlDbType. varChar, 255); cmd. parameters ["@ fldName"]. value = orderField; cmd. parameters. add ("@ OrderType", S QlDbType. tinyInt); cmd. parameters ["@ OrderType"]. value = orderType; cmd. parameters. add ("pageIndex", SqlDbType. int); cmd. parameters ["pageIndex"]. value = pageIndex; cmd. parameters. add ("pageSize", SqlDbType. tinyInt); cmd. parameters ["pageSize"]. value = pageSize; cmd. parameters. add ("strWhere", SqlDbType. varChar, 1500); cmd. parameters ["strWhere"]. value = where; cmd. parameters. add ("@ doCount", SqlDbType. ti NyInt); cmd. parameters ["@ doCount"]. value = 0; cmd. parameters. add ("@ key", SqlDbType. varChar, 255); cmd. parameters ["@ key"]. value = key; SqlDataAdapter DA = new SqlDataAdapter (cmd); DataSet ds = new DataSet (); DA. fill (ds); conn. close (); conn. dispose (); recordCount = GetRecordCount (table, where); return ds. tables [0];} number of returned records /// <summary> /// number of returned records /// </summary> /// <param name = "table"> table name </param>/ // <Param name = "where"> query condition </param> // <returns> </returns> public int GetRecordCount (string table, string where) {int RecordCount = 0; openConn (); SqlCommand cmd = new SqlCommand ("TZFX_ZHDD_P_Page", conn); cmd. commandType = CommandType. storedProcedure; cmd. parameters. add ("@ tblName", SqlDbType. varChar, 800); cmd. parameters ["@ tblName"]. value = table; cmd. parameters. add ("strWhere", SqlDbType. varChar, 1500); cmd. parameters ["strWhere"]. value = where; cmd. parameters. add ("@ doCount", SqlDbType. tinyInt); cmd. parameters ["@ doCount"]. value = 1; cmd. prepare (); SqlDataReader dr = cmd. executeReader (CommandBehavior. closeConnection); while (dr. read () {RecordCount = int. parse (dr [0]. toString ();} // conn. close (); // conn. dispose (); dr. close (); dr. dispose (); return RecordCount;} Get the paging data stored procedure (multiple sorting fields) USE [Table name] GO/ * ***** Object: StoredProcedure [dbo]. [P_Page_ManyOrderFile] Script Date: 03/06/2013 09:32:23 ******/SET ANSI_NULLS OFFGOSET QUOTED_IDENTIFIER offgoalter procedure [dbo]. [P_Page_ManyOrderFile] @ tblName varchar (800), -- table name @ strGetFields varchar (1000) = '*', -- columns to be returned @ fldName varchar (255) = '', -- sorting field name @ PageSize int = 10, -- page size @ PageIndex int = 1, -- page number @ doCount tinyint = 0, -- returns the total number of records. If the value is not 0, @ OrderType is returned. Tinyint = 0, -- set the sorting type. If the value is not 0, it is sorted in descending order @ strWhere varchar (1500) = '', -- Query condition (Note: Do not add where) @ key varchar (255) -- primary key, used for paging ASdeclare @ strSQL varchar (5000) -- subject sentence declare @ strTmp varchar (110) -- temporary variable declare @ strOrder varchar (400) -- sort type if @ doCount! = 0 begin if @ strWhere! = ''Set @ strSQL = "select count (*) as total from" + @ tblName + "where" + @ strWhereelseset @ strSQL = "select count (*) as total from "+ @ tblName -- the above Code indicates that if @ doCount is not passed over 0, the total number of statistics will be executed. All the following codes are 0 @ doCount: endelsebeginif @ OrderType! = 0 beginset @ strTmp = "not in (select" set @ strOrder = "order by" + @ fldName + "desc" -- if @ OrderType is not 0, run the descending order, this sentence is very important! Endelsebeginset @ strTmp = "not in (select" set @ strOrder = "order by" + @ fldName + "asc" endif @ PageIndex = 1 beginif @ strWhere! = ''Set @ strSQL = "select top" + str (@ PageSize) + "" + @ strGetFields + "from" + @ tblName + "where" + @ strWhere + "" + @ strOrderelseset @ strSQL = "select top" + str (@ PageSize) + "" + @ strGetFields + "from" + @ tblName + @ strOrder -- execute the above Code on the first page, this will speed up the execution. endelsebegin -- the following code gives @ strSQL the SQL code set @ strSQL = "select top" + str (@ PageSize) for real execution) + "" + @ strGetFields + "from" + @ tblName + "where [" + @ key + "]" + @ StrTmp + "[" + @ key + "] from (select top" + str (@ PageIndex-1) * @ PageSize) + "[" + @ key + "] from" + @ tblName + @ strOrder + ") as tblTmp)" + @ strOrderif @ strWhere! = ''Set @ strSQL = "select top" + str (@ PageSize) + "" + @ strGetFields + "from" + @ tblName + "where [" + @ key + "]" + @ strTmp + "[" + @ key + "] from (select top "+ str (@ PageIndex-1) * @ PageSize) + "[" + @ key + "] from" + @ tblName + "where" + @ strWhere + "" + @ strOrder + ") as tblTmp) and "+ @ strWhere +" "+ @ strOrderend endexec (@ strSQL) returns the number of records stored procedure USE [Table name] GO/****** Object: storedProcedure [dbo]. [TZ FX_ZHDD_P_Page] Script Date: 03/06/2013 09:55:24 *****/SET ANSI_NULLS OFFGOSET QUOTED_IDENTIFIER offgoalter procedure [dbo]. [TZFX_ZHDD_P_Page] @ tblName varchar (800), -- table name @ strGetFields varchar (1000) = '*', -- column to be returned @ fldName varchar (255) = '', -- sorting field name @ PageSize int = 10, -- page size @ PageIndex int = 1, -- page number @ doCount tinyint = 0, -- total number of records returned, if the value is not 0, @ OrderType tinyint = 0 is returned. -- set the sorting type. If the value is not 0, @ strWhere varcha is returned in descending order. R (1500) = ''-- Query condition (Note: Do not add where) ASdeclare @ strSQL varchar (5000) -- subject sentence declare @ strTmp varchar (110) -- temporary variable declare @ strOrder varchar (400) -- sorting type if @ doCount! = 0 begin if @ strWhere! = ''Set @ strSQL = "select count (*) as total from" + @ tblName + "where" + @ strWhereelseset @ strSQL = "select count (*) as total from "+ @ tblName -- the above Code indicates that if @ doCount is not passed over 0, the total number of statistics will be executed. All the following codes are 0 @ doCount: endelsebeginif @ OrderType! = 0 beginset @ strTmp = "<(select min" set @ strOrder = "order by [" + @ fldName + "] desc" -- if @ OrderType is not 0, this sentence is very important! Endelsebeginset @ strTmp = "> (select max" set @ strOrder = "order by [" + @ fldName + "] asc" endif @ PageIndex = 1 beginif @ strWhere! = ''Set @ strSQL = "select top" + str (@ PageSize) + "" + @ strGetFields + "from" + @ tblName + "where" + @ strWhere + "" + @ strOrderelseset @ strSQL = "select top" + str (@ PageSize) + "" + @ strGetFields + "from" + @ tblName + @ strOrder -- execute the above Code on the first page, this will speed up the execution. endelsebeginwww.2cto.com -- the following code gives @ strSQL the SQL code set @ strSQL = "select top" + str (@ PageSize) for real execution) + "" + @ strGetFields + "from" + @ tblName + "where ["+ @ FldName +"] "+ @ strTmp +" (["+ @ fldName +"]) from (select top "+ str (@ PageIndex-1) * @ PageSize) + "[" + @ fldName + "] from" + @ tblName + @ strOrder + ") as tblTmp)" + @ strOrderif @ strWhere! = ''Set @ strSQL = "select top" + str (@ PageSize) + "" + @ strGetFields + "from" + @ tblName + "where [" + @ fldName + "]" + @ strTmp + "([" + @ fldName + "]) from (select top "+ str (@ PageIndex-1) * @ PageSize) + "[" + @ fldName + "] from" + @ tblName + "where" + @ strWhere + "" + @ strOrder + ") as tblTmp) and "+ @ strWhere +" "+ @ strOrderend endexec (@ strSQL)

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.