i am refering this article
https://www.aspsnippets.com/Articles/Search-and-Filter-GridView-as-you-type-in-TextBox-using-jQuery-AJAX-in-ASPNet.aspx
namespace Quiz_Inventory_Management_System.User
{
public partial class UpdateProject : System.Web.UI.Page
{
string name;
string teamleadname;
private static int PageSize = 10;
protected void Page_Load(object sender, EventArgs e)
{
name = (string)Session["UserName"];
teamleadname = (string)Session["TeamLead"];
if (!IsPostBack)
{
BindDummyRow();
}
}
private void BindDummyRow()
{
string con = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
SqlDataAdapter da = new SqlDataAdapter("select Project_CRF_ID,Proj_ID,Teams,Proj_Name,Proj_Team_Lead,Proj_Team_Member,Proj_Status,Comment,Proj_Details from Project_Inventory_TBL", con);
DataTable dt = new DataTable();
da.Fill(dt);
gvCustomers.DataSource = dt;
gvCustomers.DataBind();
}
[WebMethod]
public static string GetCustomers(string searchTerm, int pageIndex)
{
string query = "[GetCustomers_Pager_Project]";
SqlCommand cmd = new SqlCommand(query);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@SearchTerm", searchTerm);
cmd.Parameters.AddWithValue("@PageIndex", pageIndex);
cmd.Parameters.AddWithValue("@PageSize", PageSize);
cmd.Parameters.Add("@RecordCount", SqlDbType.Int, 4).Direction = ParameterDirection.Output;
return GetData(cmd, pageIndex).GetXml();
}
private static DataSet GetData(SqlCommand cmd, int pageIndex)
{
string strConnString = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataSet ds = new DataSet())
{
sda.Fill(ds, "Project_Inventory_TBL");
DataTable dt = new DataTable("Pager");
dt.Columns.Add("PageIndex");
dt.Columns.Add("PageSize");
dt.Columns.Add("RecordCount");
dt.Rows.Add();
dt.Rows[0]["PageIndex"] = pageIndex;
dt.Rows[0]["PageSize"] = PageSize;
dt.Rows[0]["RecordCount"] = cmd.Parameters["@RecordCount"].Value;
ds.Tables.Add(dt);
return ds;
}
}
}
}
}
}
<%@ Page Title="" Language="C#" MasterPageFile="~/User/Site1.Master" AutoEventWireup="true" CodeBehind="UpdateProject.aspx.cs" Inherits="Quiz_Inventory_Management_System.User.UpdateProject" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<script src="Script/jquery.min.js"></script>
<script src="Script/ASPSnippets_Pager.min.js"></script>
<script type="text/javascript">
$(function () {
GetCustomers(1);
});
$("[id*=txtSearch]").live("keyup", function () {
GetCustomers(parseInt(1));
});
$(".Pager .page").live("click", function () {
GetCustomers(parseInt($(this).attr('page')));
});
function SearchTerm() {
return jQuery.trim($("[id*=txtSearch]").val());
};
function GetCustomers(pageIndex) {
$.ajax({
type: "POST",
url: "UpdateProject.aspx/GetCustomers",
data: '{searchTerm: "' + SearchTerm() + '", pageIndex: ' + pageIndex + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
}
var row;
function OnSuccess(response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
var customers = xml.find("Customers");
if (row == null) {
row = $("[id*=gvCustomers] tr:last-child").clone(true);
}
$("[id*=gvCustomers] tr").not($("[id*=gvCustomers] tr:first-child")).remove();
if (customers.length > 0) {
$.each(customers, function () {
var customer = $(this);
$("td", row).eq(0).html($(this).find("Project_CRF_ID").text());
$("td", row).eq(1).html($(this).find("Proj_ID").text());
$("td", row).eq(2).html($(this).find("Proj_Name").text());
$("td", row).eq(3).html($(this).find("Teams").text());
$("td", row).eq(4).html($(this).find("Proj_Team_Lead").text());
$("td", row).eq(5).html($(this).find("Proj_Team_Member").text());
$("td", row).eq(6).html($(this).find("Proj_Status").text());
$("td", row).eq(7).html($(this).find("Comment").text());
$("td", row).eq(8).html($(this).find("Proj_Details").text());
$("[id*=gvCustomers]").append(row);
row = $("[id*=gvCustomers] tr:last-child").clone(true);
});
var pager = xml.find("Pager");
$(".Pager").ASPSnippets_Pager({
ActiveCssClass: "current",
PagerCssClass: "pager",
PageIndex: parseInt(pager.find("PageIndex").text()),
PageSize: parseInt(pager.find("PageSize").text()),
RecordCount: parseInt(pager.find("RecordCount").text())
});
$(".ContactName").each(function () {
var searchPattern = new RegExp('(' + SearchTerm() + ')', 'ig');
$(this).html($(this).text().replace(searchPattern, "<span class = 'highlight'>" + SearchTerm() + "</span>"));
});
} else {
var empty_row = row.clone(true);
$("td:first-child", empty_row).attr("colspan", $("td", row).length);
$("td:first-child", empty_row).attr("align", "center");
$("td:first-child", empty_row).html("No records found for the search criteria.");
$("td", empty_row).not($("td:first-child", empty_row)).remove();
$("[id*=gvCustomers]").append(empty_row);
}
};
</script>
</asp:Content>