Layer-3 + temporary table storage process + clever use of JSON + Cheap Trick image loading-> refreshing pagination brainstorm reflection + generic construction of common functions

Source: Internet
Author: User

1. load data display and load images

2. Return JSON data and paging strings

3. Refreshing pagination

 

4. Reflection + generic --> simple general demo

Some people have questioned the reflection of brainstorming + generic construction of common functions.

5. Front-end

View code

  <  Script  Type = "Text/JavaScript"  >  $ (  Function  () {Loaddata ();});  Function  Loaddata (PARAM) {$. getjson (  "  Ajax/userinfolist. ashx  "  , Param, Function  (Data) {$ (  "  . Wr  "  ). Remove (); $ (  "  # Tabuser  "  ). Append (data. userjson); $ (  " # Divpager  "  Pai.html (data. pagerjson); pagelink () ;}) $ (  "  # Divpager  "  Pai.html (  "    "  );} Function  Pagelink () {$ (  "  . Pagelink  "  ). Click (  Function  (){  VaR  Params  = $ (  This  ). ATTR (  "  Href  "  ); Params  =  Params. substring (  1  , Params. Length); loaddata (Params ); Return   False  ;  //  Block jump  });}  </  Script  >  </  Head  >  <  Body Style  = "Font-family: lucida console ;"  >      <  Div  ID  = "Divuserlist"  >        <  Table  ID  = "Tabuser"   >          <  Thead  > <  Th > ID </  Th  > <  Th  > Username </  Th  > <  Th  > Operation </  Th  > </  Thead  >       </  Table  >      </  Div  >      <  Div  ID  = "Divpager"  Class  = "Pager"  >          </  Div  >  </ Body  > 

6. Background

View code

   Int Totalcount = 0  ;  Int Pagesize = context. request [ "  Pagesize  " ] = Null ? 3 : Int . Parse (context. request [ "  Pagesize  "  ]);  Int Pageindex = context. request [ "  Pageindex  " ] = Null ? 1 : Int . Parse (context. request [ "  Pageindex  " ]);  VaR Data = userservice. loadpageentities (pagesize, pageindex, Out  Totalcount); stringbuilder sb = New  Stringbuilder ();  Foreach ( VaR Item In  Data) {sb. append (  String . Format ( " <Tr class = 'util'> <TD> {0} </TD> <TD >{1} </TD> <a href = '? Delid = {2} '> Delete </a> </TD> </tr>  "  , Item. ID, item. username, item. ID ));}  VaR Pagehtml = New  Tuzipager (). generatepagehtml (pageindex, pagesize, totalcount );  VaR Jsondataserializer = New {Userjson = sb. tostring (), pagerjson = Pagehtml}; javascriptserializerJavascriptSerializer =New  Javascriptserializer ();  String JSON = Javascriptserializer. serialize (jsondataserializer );  If ( String . Isnullorempty (context. request [ "  Pageindex  " ]) & String . Isnullorempty (context. request [ "  Pagesize  " ]) {Thread. Sleep (  2000  );} Context. response. Write (JSON ); 

7. Stored Procedures and tables used

Create Table [DBO]. [userinfo] ([ID] [int] Identity (1,1) not null, [username] [nvarchar] (50) Collate chinese_prc_ci_as null, constraint [pk_userinfo] primary key clustered ([ID] ASC) with (pad_index = OFF, ignore_dup_key = OFF) on [primary]) on [primary]/****** Stored Procedure script Date: 01/21/2013 17:14:29 ******/alter proc proc_page @ pagesize int, @ pageindex int, @ totalcount int outputas select * into # TMP from (select ID, username from userinfo) T declare @ sqlpage nvarchar (500 ); set @ sqlpage = 'select * from' + '(select ID, username, row_number () over (order by ID) num from # TMP) t' + 'where T. num between ('+ STR (@ pageIndex-1) * @ pagesize + 1) +') and ('+ STR (@ pageindex * @ pagesize) + ') 'exec (@ sqlpage) print @ sqlpage select @ totalcount = count (1) from # TMP; drop table # tmpdeclare @ count int exec proc_page 3, 2, @ count output

Conclusion: If you are bored in the afternoon, write this.CodeHope to make progress in the same agriculture and code community as me, and give me more advice.

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.