Hi ramco1917,
Please refer below sample.
Database
For this example I have used of Northwind database that you can download using the link given below.
Download Northwind Database
HTML
<asp:TextBox ID="txtSearch" runat="server"></asp:TextBox><br />
<asp:Button ID="btnFilter" runat="server" Text="Search" OnClick="OnSearch" />
<asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField DataField="OrderID" HeaderText="OrderID" />
<asp:BoundField DataField="ShipName" HeaderText="ShipName" />
<asp:BoundField DataField="ShipCountry" HeaderText="ShipCountry" />
</Columns>
</asp:GridView>
Namespace
C#
using NORTHWINDModel;
VB.Net
Imports NORTHWINDModel
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
NORTHWINDEntities entities = new NORTHWINDEntities();
List<Order> orders = entities.Orders.Take(10).ToList();
BindGrid(orders);
}
}
protected void OnSearch(object sender, EventArgs e)
{
NORTHWINDEntities entities = new NORTHWINDEntities();
List<Order> orders = entities.Orders.Take(10).ToList();
if (!string.IsNullOrEmpty(txtSearch.Text.Trim()))
{
orders = orders.Where(x => x.ShipCountry == txtSearch.Text.Trim()).ToList();
}
BindGrid(orders);
}
private void BindGrid(List<Order> orders)
{
gvOrders.DataSource = orders;
gvOrders.DataBind();
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim entities As NORTHWINDEntities = New NORTHWINDEntities()
Dim orders As List(Of Order) = entities.Orders.Take(10).ToList()
BindGrid(orders)
End If
End Sub
Protected Sub OnSearch(ByVal sender As Object, ByVal e As EventArgs)
Dim entities As NORTHWINDEntities = New NORTHWINDEntities()
Dim orders As List(Of Order) = entities.Orders.Take(10).ToList()
If Not String.IsNullOrEmpty(txtSearch.Text.Trim()) Then
orders = orders.Where(Function(x) x.ShipCountry = txtSearch.Text.Trim()).ToList()
End If
BindGrid(orders)
End Sub
Private Sub BindGrid(ByVal orders As List(Of Order))
gvOrders.DataSource = orders
gvOrders.DataBind()
End Sub
Screenshot