views:

29

answers:

3

Hello all,

for example i have some list with 120 entries.

 Threads = new List<Thread>();

and i will return to show in my view just 10 of them.

I have a properties like, TotalCount, TotalPages, PageSize=10, PageIndex. How can I do that?

Take care, Ragims

A: 

Do a google search on "Paging with LINQ" and you'll get a ton of ideas. LINQ really makes it easier to do this sort of thing.

Patrick Steele
all my logic is already with sql statements in code. its hard to use linq now
Ragims
What do you mean it's hard to use LINQ?
Bertrand Marron
can i use a linq if i have already implemented logic with c# and sql statements as SqlCommand.Text?? I never worked with linq. I dont know if i canuse it additionaly to my already implemented logic
Ragims
@Ragmis: Your question doesn't say anything about SQL statements. Including that in your original question would have gotten you better answers.
Patrick Steele
Bertrand Marron: I said LINQ makes it easier.
Patrick Steele
+3  A: 

How about Threads.Skip(PageIndex*PageSize).Take(PageSize) ?

(Edit: this depends on linq extension methods)

jdv
do you have some idea to do that with poor sql statements and c#?
Ragims
Correct me if I'm wrong, but won't this give you the page after the one you're looking for? Page 1 will skip 1 * 10 and give you the next 10 which is results 11 - 20.
Justin Niessner
yes you are absolutely right, but i not using linq in my project. i am trying to do it without linq.
Ragims
+1  A: 

Use a combination of Skip and Take:

var threads = new List<Thread>();

// Fill the list

threads.Skip(PageSize * (PageIndex - 1)).Take(PageSize);

Or, if PageIndex is zero based (the first page is PageIndex = 0) then:

threads.Skip(PageSize * PageIndex).Take(PageSize);
Justin Niessner
i cant use a linq... because all my logic is altready build with c# and sql statements
Ragims
@Ragims - I'm confused. You're still filling a List and you want to page through the List. Once the List is filled, your logic and SQL has already been run, has it not?
Justin Niessner