Use LINQ for List partition/area

Source: Internet
Author: User

Use LINQ for List partition/area

The server controls such as listview do not need to be said too much. Drag the controls to change the scoring feature. It will not waste everyone's time.

In this case, I only thought about the idea and the power of the generation. A row-specific operation on a set in the LINQ ‑based environment can be used for segmentation. pageSize: the size of the shard, that is, the number of rows shown in a batch curretPage: Before the Shard is created. let's take a look at this. totalPages: Total taotalPages = (int) Math. ceiling (List <T> (). count/(double) pageSize); this sort List <T> () is your set. for example, DataRow. obtain the data to be displayed. var dataList = (from r in List <T> ()). Skip(CurretPage * pageSize ). Take(PageSize) The last vertex. If pageSize is greater than limit count, only the list of remaining limit count is obtained. does not throw exception. for the next request, you only need to modify the currenPage. the specific design will not be described. of course the above method for asp.net is used in the same way. hope to help you.
How to Use the linq pagination Method

Assume that the class corresponding to your news table is
Public class NewsInfo
{
Public int ID {get; set ;}
Public string Title {get; set ;}

}

First, initialize a news set and obtain data.
List <NewsInfo> news = GetdatafromDB ();

Then call the method as follows:
Var result GetIenumberable <NewsInfo> (news, x => x. ID> 3, x => x. Title, 10, 1 );
Explanations:
1st parameters are your data, 2nd Are filtering conditions, 3rd are sorting fields (and must be of the String type), and 4th are Page Size, the first page is the page currently displayed.

In mvc3, pagination is not used. I get a List of models and how to pagination

/// <Summary>
///
/// </Summary>
/// <Param name = "PageNum"> current page </param>
/// <Param name = "PageSize"> Number of lines displayed on each page </param>
/// <Returns> </returns>
Public static List <string> GetPageList (int PageNum, int PageSize)
{
List <string> ls = getList (); // assume that you obtain the total list
List <string> lsPage = new List <string> (); // declare an lsPage to display information on each page, list is used now
Int PageBeg = (PageNum-1) * PageSize; // you can specify the start subscript.
Int PageEnd = PageNum * PageSize; // end subscript
For (int I = PageBeg; I <PageEnd; I ++)
{
LsPage. Add (ls [I]); // cyclically Add all information on the current page
}
Return lsPage; // return the information
}

But I really want to say something. Using List for paging is not scientific .... Rather paging in the database .... Haha

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.