ASP. NET mvc3 uses the scroll bar to load data

Source: Internet
Author: User

Loading data with a scroll bar is a popular paging method.

Operation Method: load more data based on the current position of the scroll bar.

There are two main forms.

1: load data while scrolling. Calculate the height of the container at the beginning. load more data when the scroll bar moves to a blank position. Like http://qing.blog.sina.com.cn/tag/%E6%97%B6%E5%B0%9A

2: scroll to the bottom and load more data when the scroll bar moves to the bottom. Similar to "Baidu pictures.

Its advantages: You can use the scroll wheel for paging without clicking a button, so that you can quickly browse the complete information without frequently clicking the paging button. The effect on mobile phones is particularly obvious.

Its disadvantage: it is not very convenient for users to quickly view some data. If users want to view the data on the back, they need to load all the data before they can find the desired data.

Implementation Method: Using ASP. net mvc + jquery framework is easier to achieve this effect (because I have not recently used webform, It is unfamiliar, so I will not show it ugly)

Loading data to the bottom is an example, which is easier to implement.

In the HTML section, div: container controls the container of the scroll bar, and Div: datalist loads the data container. Height: 420px; overflow-Y: auto; style must be added to the container.

JS is mainly used to operate the scroll bar of the iner container to determine whether to remove the bottom.
You can use $ ("# container") [0]. scrolltop + $ ("# container "). height () >=$ ("# container") [0]. scrollheight-10. For details about these attributes, check them on the network,
Note that-10 is mainly used to ensure compatibility with chrome browsers. Different browsers may parse the attributes of the scroll bar. If the list style is too complex, you need to debug it repeatedly.

 1   Function  Add_data (){  2       VaR Scrolltop = $ ("# container") [0 ]. Scrolltop;  3       If (! Complete && Loaded ){  4           If (Scrolltop + $ ("# container"). Height () >=$ ("# container") [0 ]. Scrollheight ){  5   Getdata ();  6   }  7   8   }  9   }  10   11   Function  Getdata (){  12 Loaded =False  ;  13   $. Ajax ({  14 URL: '@ URL. Action ("mainlistpanel", "home ")' ,  15 Type: 'post' ,  16   Data :{  17   Createtime: maxtime,  18   Skipcount: skipcount,  19  Takecount: takecount  20   },  21 Datatype: 'html' ,  22 Timeout: 10000 ,  23 Error: Function () {Alert ('error loading' );},  24 Beforesend: Function  (){  25              //  $ ("# Datalist"). append (" ");  26 $ ("# Box" ). Show ();  27   },  28 Success: Function  (Result ){  29 Loaded = True  ;  30 $ ("# Box"). Hide ();  31               //  $ (". Loading"). Remove ();  32 $ ("# Datalist" ). Append (result );  33 Count ++ ;  34   }  35   });  36 }

View code

The server uses the powerful orderbydescending, skip, and take methods of LINQ to filter out loaded data.

Download source code

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.