Search data in Gridview on Textbox Key press event using JQuery in Asp.Net- C#

First of all add the following .js file, Link and the JavaScript to your <Head> tag ::

<head runat="server">
<script type="text/javascript" src=""></script>
<script type="text/javascript" src="js/quicksearch.js"></script>
<script type="text/javascript">
    $(function () {
        $('.search_textbox').each(function (i) {
            $(this).quicksearch("[id*=gvDetails] tr:not(:has(th))", {
                'testQuery': function (query, txt, row) {
                    return $(row).children(":eq(" + i + ")").text().toLowerCase().indexOf(query[0].toLowerCase()) != -1;

// This Script dynamically searches the GridView cells and filters out the unwanted rows and displays only the records that matches the input search term.

Now add the following code inside your <Body> tag ::

 <form id="form1" runat="server">
       <asp:GridView ID="gvDetails" HeaderStyle-BackColor="AliceBlue"
            HeaderStyle-ForeColor="Black" runat="server"
        <asp:BoundField DataField="UserId" HeaderText="User Id" ItemStyle-Width="50" />
        <asp:BoundField DataField="Name" HeaderText="Name" ItemStyle-Width="150" />
        <asp:BoundField DataField="Designation" HeaderText="Designation" ItemStyle-Width="200" />
        <asp:BoundField DataField="Department" HeaderText="Department" ItemStyle-Width="150" />

And finally add the following code in the code page ::

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class SearchInGridViewRowaspx : System.Web.UI.Page
    protected void Page_Load(object sender, EventArgs e)
        if (!IsPostBack)

    private void BindData()
        gvDetails.Columns[4].Visible = false;
        gvDetails.DataSource = this.getData();

    private DataTable getData()
        if (ViewState["Details"] != null)
            return (DataTable)ViewState["Details"];

        DataTable dt = new DataTable();
        dt.Columns.Add("UserId", typeof(Int32));
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("Designation", typeof(string));
        dt.Columns.Add("Department", typeof(string));

        DataRow dr = dt.NewRow();
        dr["UserId"] = 101;
        dr["Name"] = "Zaheer";
        dr["Designation"] = "Associate Technical Consultant";
        dr["Department"] = ".Net";

        dr = dt.NewRow();
        dr["UserId"] = 12;
        dr["Name"] = "Anish";
        dr["Designation"] = "Technical Consultant";
        dr["Department"] = "CRM";

        dr = dt.NewRow();
        dr["UserId"] = 113;
        dr["Name"] = "Manish";
        dr["Designation"] = "Navision Consultant";
        dr["Department"] = "Navision";

        dr = dt.NewRow();
        dr["UserId"] = 4;
        dr["Name"] = "Ravish";
        dr["Designation"] = "Tech Lead";
        dr["Department"] = "CRM";

        ViewState["Details"] = dt;
        return dt;

// Below a new header having textbox in each cell is created and added to gridview.
// KeyPress event of textbox on each column is used to search data in respective column
// CssClass property is set for each TextBox with value "search_textbox" to apply the jQuery QuickSearch plugin client side using the jQuery CSS class selector.

    protected void gvDetails_DataBound(object sender, EventArgs e)
        GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
        for (int i = 0; i < gvDetails.Columns.Count - 1; i++)
            TableHeaderCell cell = new TableHeaderCell();
            TextBox txtSearch = new TextBox();
            txtSearch.Attributes["placeholder"] = gvDetails.Columns[i].HeaderText;
            txtSearch.CssClass = "search_textbox";
        gvDetails.HeaderRow.Parent.Controls.AddAt(1, row);

Link for quciksearch.js ::

Click here to get "QuickSearch.js" file. Just copy text and save file as "quicksearch.js"

Or, Visit this link::


  1. dude...please provide quicksearch.js


  2. Hi, Is it possible to search in all the gridview columns with only one textbox

    1. Goto this link, it will be helpful ::

    2. Thanks for your help, I think that this is also searching in one column.

    3. You search all column add condition

  3. How do I connect this to my exiting SQL Table? Can you please pot the code snippet? Thanks and I appreciate your help.

  4. I added a editing button to my gridview and when i click it the searchboxes that were created by the databound event disappear, how should i solved this issue?

    thanx in advance

  5. not working on controls postback..!

  6. Not working with gridview having paging..

  7. QuickSearch is searching fine.. But if the Gridview is having paging, then it is only searching for the single Gridview page. is it able to search in all rows of Gridview beyond the paging?


Post a Comment

Popular posts from this blog

StateCode and StatusCode Values for mostly used entities in Microsoft Dynamics CRM 2013

Dumps for Microsoft Dynamics CRM MB2-703 Practice Exam Questions Free

How to import CSV files into DataTable in C#

How to show enlarge image when mouse hover on image or link in Asp.Net(c#) using JavaScript

go to top image