Hi nauna,
Use Swich case to build your query.
Check this example. Now please take its reference and correct your code.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<asp:DropDownList runat="server" Width="200px" ID="ddlFilters">
<asp:ListItem Text="All" Value="All" />
<asp:ListItem Text="=" Value="=" />
<asp:ListItem Text=">" Value=">" />
<asp:ListItem Text="<" Value="<" />
<asp:ListItem Text="<=" Value="<=" />
<asp:ListItem Text=">=" Value=">=" />
</asp:DropDownList>
<asp:TextBox runat="server" ID="txtValue" />
<asp:Button ID="Button1" Text="Search" runat="server" OnClick="Search" />
<br />
<br />
<asp:GridView runat="server" ID="gvEmployees" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="EmployeeId" HeaderText="Id" />
<asp:BoundField DataField="FirstName" HeaderText="Name" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="Country" HeaderText="Country" />
</Columns>
</asp:GridView>
Code
C#
protected void Search(object sender, EventArgs e)
{
NorthwindModel.NorthwindEntities entities = new NorthwindModel.NorthwindEntities();
List<NorthwindModel.Employee> query = new List<NorthwindModel.Employee>();
string filter = ddlFilters.SelectedValue;
int value = Convert.ToInt32(!string.IsNullOrEmpty(txtValue.Text) ? txtValue.Text : "0");
switch (filter)
{
case "=":
query = (from c in entities.Employees
where c.EmployeeID == value
select c).ToList();
break;
case ">":
query = (from c in entities.Employees
where c.EmployeeID > value
select c).ToList();
break;
case "<":
query = (from c in entities.Employees
where c.EmployeeID < value
select c).ToList();
break;
case ">=":
query = (from c in entities.Employees
where c.EmployeeID >= value
select c).ToList();
break;
case "<=":
query = (from c in entities.Employees
where c.EmployeeID <= value
select c).ToList();
break;
default:
query = (from c in entities.Employees
select c).ToList();
break;
}
gvEmployees.DataSource = query;
gvEmployees.DataBind();
}
VB.Net
Protected Sub Search(ByVal sender As Object, ByVal e As EventArgs)
Dim entities As NorthwindModel.NorthwindEntities = New NorthwindModel.NorthwindEntities()
Dim query As List(Of NorthwindModel.Employee) = New List(Of NorthwindModel.Employee)()
Dim filter As String = ddlFilters.SelectedValue
Dim value As Integer = Convert.ToInt32(If(Not String.IsNullOrEmpty(txtValue.Text), txtValue.Text, "0"))
Select Case filter
Case "="
query = (From c In entities.Employees Where c.EmployeeID = value Select c).ToList()
Case ">"
query = (From c In entities.Employees Where c.EmployeeID > value Select c).ToList()
Case "<"
query = (From c In entities.Employees Where c.EmployeeID < value Select c).ToList()
Case ">="
query = (From c In entities.Employees Where c.EmployeeID >= value Select c).ToList()
Case "<="
query = (From c In entities.Employees Where c.EmployeeID <= value Select c).ToList()
Case Else
query = (From c In entities.Employees Select c).ToList()
End Select
gvEmployees.DataSource = query
gvEmployees.DataBind()
End Sub
Screenshot