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

How to use SQL like Operator in LINQ using ASP.NET C#

Dear viewers I will show how use SQL like Operator in LINQ using ASP.NET C# normally we use SQL like operator to search any key word type data from database. In this case there is good solution for C# developer LINQ Contains method can be used to do same task. At first I have created a collection to create virtual data to supply grid-view. But we assume data will be fetched from database .After creating Student list collection A textbox and a submit button has been taken to search student list using key word like a,b,c,d… and many more

SQL like Operator in LINQ


<html xmlns="">
<head runat="server">
  <style type="text/css">
  color: #CC3300;
  color: #99CC00;
  <form id="form1" runat="server">
  <table width="100%">
  <td colspan="3">
  <h2 class="style4">Linq Like Operator Example</h2></td>
  <td width="260" class="style1">
  Enter Name (Any Contain Cahracter)
  <td width="10">
  <asp:TextBox ID="txtContactsSearch" runat="server"></asp:TextBox>
  <asp:Button ID="btnSubmit" runat="server" Text="Search" OnClick="btnSubmit_Click" />
  <td width="260">
  <td width="10">
  <td colspan="3">
  <asp:GridView ID="gvLikeOperator" runat="server" AutoGenerateColumns="False" CellPadding="4"
  ForeColor="#333333" GridLines="None" Width="50%">
  <AlternatingRowStyle BackColor="White" />
  <asp:BoundField DataField="StudentName" HeaderText="Student Name" ItemStyle-HorizontalAlign="Center">
  <ItemStyle HorizontalAlign="Center" />
  <EditRowStyle BackColor="#2461BF" />
  <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
  <HeaderStyle BackColor="#0099FF" Font-Bold="True" ForeColor="White" />
  <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
  <RowStyle BackColor="#EFF3FB" />
  <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
  <SortedAscendingCellStyle BackColor="#F5F7FB" />
  <SortedAscendingHeaderStyle BackColor="#6D95E1" />
  <SortedDescendingCellStyle BackColor="#E9EBEF" />
  <SortedDescendingHeaderStyle BackColor="#4870BE" />


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 LinqLikeOperator : System.Web.UI.Page
  protected void Page_Load(object sender, EventArgs e)
  protected void btnSubmit_Click(object sender, EventArgs e)
  if (txtContactsSearch.Text.Trim() != string.Empty)
  var data = (from m in GetStudentList()
  where m.StudentName.Contains(txtContactsSearch.Text.Trim())
  select m);
  gvLikeOperator.DataSource = data;
  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"}
  return StudentStudents;
  public class Student
  public int StudentID { get; set; }
  public string StudentName { get; set; }

Out Put


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 control dynamically
Learn HTML for beginner
DataList example in C Sharp
Mail sending in 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# c # basic tutorial
How to use ajax toolkit in C#
How to use different types of validation control using c#
How to use grid view in c#
Protected by Copyscape Online Plagiarism Detection