.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> LINQ >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Skipping one record and taking the rest of the records from a list

Posted By:Parvathi       Posted Date: June 17, 2010    Points: 10    Category: LINQ    URL: http://www.dotnetspark.com  

Creates a student list sorted the list in ascending order
 

 

Aspx Page

 
        
            

Skipping and Taking

 

Code behind File

 

 List lstStudents = GetStudents();
       
        static List GetStudents()
        {
            List students = new List
              {
                new Student() { RollNumber = 1,Name ="Minu " , Section = 1 ,HostelNumber=1 },
                new Student() { RollNumber = 2,Name ="Bimal " , Section = 2 ,HostelNumber=2 },
                new Student() { RollNumber = 3,Name ="Parvathi " , Section = 3 ,HostelNumber=1 },
                new Student() { RollNumber = 4,Name ="Sanju" , Section = 3 ,HostelNumber=2 },
                new Student() { RollNumber = 5,Name ="Piyush " , Section = 2 ,HostelNumber=1 },
                new Student() { RollNumber = 6,Name ="Unni " , Section = 1 ,HostelNumber=2},
                new Student() { RollNumber = 7,Name ="Roshni " , Section = 1 ,HostelNumber=1 },
                new Student() { RollNumber = 8,Name ="Jiss " , Section = 2 ,HostelNumber=2 },
                new Student() { RollNumber = 9,Name ="Sudeepthy " , Section = 3 ,HostelNumber=1 },
                new Student() { RollNumber = 10,Name ="Tony " , Section = 3 ,HostelNumber=2 }
               };
            return students;
        }









  protected void btnSkip_Click(object sender, EventArgs e)
        {
            GridView2.DataSource = (from lst in lstStudents

                                    orderby lst.Name ascending

                                    select lst).Skip(1).Take(5);

            GridView2.DataBind();
        }

     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend