Click here to Skip to main content
15,884,472 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello,
I have autocomplete gridview which will filter when i keypress in separate textbox. It is working fine in filter part. but now i want to select the row from table and store the data in sessions. can anyone please explain how i can do it.

my jquery code is:-

JavaScript
$("#popup").ready(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: "Home.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("Id").text());
            $("td", row).eq(1).html($(this).find("Patient_First_Name").text());
            $("td", row).eq(2).html($(this).find("Patient_DOB").text());
            $("td", row).eq(3).html($(this).find("Patient_Home_Phone").text());
            $("td", row).eq(4).html($(this).find("Patient_Account_No").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);
    }
};



my aspx code is:-

ASP.NET
<asp:GridView ID="gvCustomers" CssClass="gridview" runat="server" AutoGenerateColumns="false" OnRowDataBound="gvCustomers_RowDataBound" OnSelectedIndexChanged="gvCustomers_SelectedIndexChanged">
                                <Columns>
                                    <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" />
                                </Columns>
                            </asp:GridView>
Posted
Comments
Sinisa Hajnal 16-Apr-15 3:17am    
Add class "filtered" or something to rows in the grid (and remove it when they are filtered out). You can select them by class name and do whatever you need. You don't even need the class name if you need all the filtered rows then you just grab whetevers visible in the grid.
saurabh_mosesram 16-Apr-15 3:23am    
how can i select row if i give it a class. do i need to use Css for that.
Sinisa Hajnal 16-Apr-15 4:11am    
$(".Pager .page")

You're alredy using class selector. Not sure what you're asking. No, class is an identifier, you don't HAVE to have css, although it is common. In this case, it is questionable if you even need the class or simply select all filtered rows directly $(".gridview tr")

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