Jquery自动完成gridview行选择 [英] Jquery autocomplete gridview row select

查看:84
本文介绍了Jquery自动完成gridview行选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有自动填充jquery gridview,它会在我输入文本框时进行过滤。我想在行中的任何地方选择并将行Id传递给会话。任何人都可以给我一些想法如何做到这一点。下面是我的Js文件。



JS: -

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.

JS:-

$("#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(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());

        $("[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);
}
};







C#: -








C#:-


protected void gvCustomers_RowDataBound(object sender, GridViewRowEventArgs e)
 {

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


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

     }
 }







< br $>


Aspx: -








Aspx:-

<asp:GridView ID="gvCustomers" CssClass="gridview" runat="server" AutoGenerateColumns="false" OnRowDataBound="gvCustomers_RowDataBound">
                            <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" />
                                <asp:TemplateField HeaderText="">
                                    <ItemTemplate>
                                        <asp:HyperLink ID="HyperLink1" runat="server" Text="test" NavigateUrl='<%# Eval("Patient_First_Name", "show.aspx?ID={0}") %>'></asp:HyperLink>
                                    </ItemTemplate>
                                </asp:TemplateField>
                            </Columns>
                        </asp:GridView>

推荐答案

#popup)。ready( function (){
GetCustomers( 1 );
});
("#popup").ready(function () { GetCustomers(1); });


[id * = txtSearch] )。live( keyup function (){
GetCustomers( parseInt 1 ));
});
("[id*=txtSearch]").live("keyup", function () { GetCustomers(parseInt(1)); });


。Pager .page)。live( 点击 function (){
GetCustomers( parseInt
(".Pager .page").live("click", function () { GetCustomers(parseInt(


这篇关于Jquery自动完成gridview行选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆