Posted by : Anwar Hossain
Category : How to use LINQ in ASP.NET C#

How to skip row in LINQ using ASP.NET C#

Dear viewers I will show how to skip row in LINQ using ASP.NET C#.I have shown a very simple example to skip row from a list. After creating a collection of student list a textbox and a submit button has been taken to submit to skip expected row from student list .After Querying data LINQ skip method can be used to skip expected row.

skip row in LINQ C#

HTML

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
  <title></title>
  <style type="text/css">
  .style1
  {
  color: #336600;
  }
  .style4
  {
  color: #99CC00;
  }
  </style>
</head>
<body>
  <form id="form1" runat="server">
  <div>
  <div>
  <table width="100%">
  <tr>
  <td colspan="3">
  <h2 class="style4">LINQ Skip Row From Database</h2></td>
 
  </tr>
  <tr>
  <td width="260" class="style1">
  <strong>Enter expected row to Skip
  </strong>
   </td>
  <td width="10">
  </td>
  <td>
  <asp:TextBox ID="txtContactsSearch" runat="server"></asp:TextBox>
  <asp:Button ID="btnSubmit" runat="server" Text="Search" OnClick="btnSubmit_Click" />
  </td>
  </tr>
  <tr>
  <td width="260">
  &nbsp;</td>
  <td width="10">
   &nbsp;</td>
  <td>
  &nbsp;</td>
  </tr>
  <tr>
  <td colspan="3">
  <asp:GridView ID="gvLikeOperator" runat="server" AutoGenerateColumns="False"
  CellPadding="4" GridLines="Horizontal" Width="40%" BackColor="White"
  BorderColor="#336666" BorderStyle="Double" BorderWidth="3px">
  <Columns>
   <asp:BoundField DataField="StudentName" HeaderText="Student Name" ItemStyle-HorizontalAlign="Center">
  <ItemStyle HorizontalAlign="Center" />
  </asp:BoundField>
  </Columns>
  <FooterStyle BackColor="White" ForeColor="#333333" />
  <HeaderStyle BackColor="#336666" Font-Bold="True" ForeColor="White" />
  <PagerStyle BackColor="#336666" ForeColor="White" HorizontalAlign="Center" />
  <RowStyle BackColor="White" ForeColor="#333333" />
  <SelectedRowStyle BackColor="#339966" Font-Bold="True" ForeColor="White" />
  <SortedAscendingCellStyle BackColor="#F7F7F7" />
  <SortedAscendingHeaderStyle BackColor="#487575" />
  <SortedDescendingCellStyle BackColor="#E5E5E5" />
   <SortedDescendingHeaderStyle BackColor="#275353" />
  </asp:GridView>
  </td>
  </tr>
  </table>
  </div>
  </div>
  </form>
</body>
</html>

CODE BEHIND

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Linq.SqlClient;
 
public partial class LinqSkipExample : System.Web.UI.Page
{
  protected void Page_Load(object sender, EventArgs e)
  {
  if (!IsPostBack)
  {
 
  gvLikeOperator.DataSource = GetStudentList();
  gvLikeOperator.DataBind();
  }
  }
  protected void btnSubmit_Click(object sender, EventArgs e)
  {
  if (txtContactsSearch.Text.Trim() != string.Empty)
  {
  var data = (from m in GetStudentList()
 
  select m).Skip(Convert.ToInt32(txtContactsSearch.Text.Trim()));
 
  gvLikeOperator.DataSource = data;
  gvLikeOperator.DataBind();
 
 
   }
  }
 
 
  private List<Student> GetStudentList()
  {
 
  List<Student> StudentStudents = new List<Student>{
  new Student{StudentID=1,  StudentName="Amin"},
  new Student{StudentID=2,  StudentName="Alomgir"},
  new Student{StudentID=3,  StudentName="Ashikur Rahman"},
  new Student{StudentID=4,  StudentName="Shamim Ahmed"},
  new Student{StudentID=5,  StudentName="Amolash"},
  new Student{StudentID=6,  StudentName="Alum"},
  new Student{StudentID=7,  StudentName="Abil"},
  new Student{StudentID=8,  StudentName="Enamul"},
  new Student{StudentID=9,  StudentName="Nahid"},
  new Student{StudentID=10,  StudentName="Asraf"},
   new Student{StudentID=11,  StudentName="Asfaq"},
  new Student{StudentID=12,  StudentName="kbil"},
  new Student{StudentID=13,  StudentName="Masum"},
  new Student{StudentID=14,  StudentName="Nasid"},
  new Student{StudentID=15,  StudentName="Babu"},
  new Student{StudentID=16,  StudentName="Titu"}
  };
 
  return StudentStudents;
 
  }
 
  public class Student
  {
  public int StudentID { get; set; }
   public string StudentName { get; set; }
  }
}
 

Out Put

Linq-skip-asp.net_-c-Sharp.png



Realted Article Headline

LINQ Average Example using ASP.NET C#
LINQ Sum Example using ASP.NET C#
LINQ Find Minimum value using ASP.NET C#
LINQ Find Max value example using ASP.NET C#
LINQ Count Row example using ASP.NET C#
LINQ Sorting Example using ASP.NET C#
LINQ Equals Example using ASP.NET C#
LINQ Where condition Example using ASP.NET C#
How to skip row in LINQ using ASP.NET C#
How to select Top row in LINQ using ASP.NET C#
How to use SQL like Operator in LINQ using ASP.NET C#
How to join two collections data using LINQ in ASP.NET C#

Article Category

How to create asp.net control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in asp.net c#
State Management in ASP C #
Basic sql tutorial for Beginner
DataTable example in ASP.Net C#
How to use LINQ in ASP.NET C#
asp.net c # basic tutorial
How to use ajax toolkit in asp.net C#
How to use different types of validation control using asp.net c#
How to use grid view in asp.net c#
Protected by Copyscape Online Plagiarism Detection