Click here to Skip to main content
15,851,335 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
I am i have autocomplete jquery gridview which will filter when i type in textbox. i want to select anywhere in the row and pass row Id to session. Can anyone can give me some idea how to do it. below is my Js file.

$("#popup").ready(function () {
$("[id*=txtSearch]").live("keyup", function () {
$(".Pager .page").live("click", function () {
function SearchTerm() {
return jQuery.trim($("[id*=txtSearch]").val());
function GetCustomers(pageIndex) {
    type: "POST",
    url: "Home.aspx/GetCustomers",
    data: '{searchTerm: "' + SearchTerm() + '", pageIndex: ' + pageIndex +       '}',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: OnSuccess,
    failure: function (response) {
    error: function (response) {
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("Id").text());
        $("td", row).eq(0).html($(this).find("Patient_First_Name").text());
        $("td", row).eq(1).html($(this).find("Patient_DOB").text());
        $("td", row).eq(2).html($(this).find("Patient_Home_Phone").text());
        $("td", row).eq(3).html($(this).find("Patient_Account_No").text());

        row = $("[id*=gvCustomers] tr:last-child").clone(true);
    var pager = xml.find("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();


protected void gvCustomers_RowDataBound(object sender, GridViewRowEventArgs e)

     if (e.Row.RowType == DataControlRowType.DataRow)

         e.Row.Attributes["onmouseover"] = "'pointer';'underline';'#81DAF5';";
         e.Row.Attributes["onmouseout"] = "'none';'#FFFFFF';";
         e.Row.ToolTip = "Click to select row";
         Page.ClientScript.RegisterForEventValidation(new System.Web.UI.PostBackOptions(this.gvCustomers, "Select$" + e.Row.RowIndex.ToString()));



<asp:GridView ID="gvCustomers" CssClass="gridview" runat="server" AutoGenerateColumns="false" OnRowDataBound="gvCustomers_RowDataBound">
                                <%--<asp:BoundField DataField="Id" HeaderText="Id" />--%>
                                <asp:BoundField DataField="Patient_First_Name" HeaderText="First Name" />
                                <asp:BoundField DataField="Patient_DOB" HeaderText="Dob" />
                                <asp:BoundField DataField="Patient_Home_Phone" HeaderText="Phone Number" />
                                <asp:BoundField DataField="Patient_Account_No" HeaderText="Account No" />
                                <asp:TemplateField HeaderText="">
                                        <asp:HyperLink ID="HyperLink1" runat="server" Text="test" NavigateUrl='<%# Eval("Patient_First_Name", "show.aspx?ID={0}") %>'></asp:HyperLink>
Thanks7872 14-Apr-15 2:06am    
Dumping whole code here won't make much sense. Where is the issue? What do you mean by 'select anywhere in the row'?

1 solution

i think you can do it behind the code like this first make your field or colum into item template and make those item into textbox then after that on textchange (*note you must put AutoPostBack="true") you can use the code below im not into C# but i think you can convert it get the value and pass it to session.

Dim row As GridViewRow = TryCast(DirectCast(sender, TextBox).Parent.Parent, GridViewRow)
       myRowIndex = row.RowIndex
       Dim IDs TextBox = DirectCast("your gridview".Rows(myRowIndex).FindControl(""your ID to find" "), TextBox)
       session("IDS") =IDs  
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900