如何为ASP.NET中的大量记录设置自动完成文本框? [英] How to set auto complete textbox for large number of records in ASP.NET?

查看:250
本文介绍了如何为ASP.NET中的大量记录设置自动完成文本框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经用c#在asp.net中设置了自动完成文本框.但是,在绑定数据库中的大量记录(例如2000条左右)时,我变得很慢.如果它正在检索大量记录(例如至少20k),那么它也不起作用.对该Web方法进行了调用,并将值从数据集中返回到列表.

我尝试过的事情:

源代码:

I have set auto complete text box in asp.net with c#. But I am getting slowness while binding huge volume of records (say 2000 or so) from the Database. If it is retrieving huge amount of record(say atleast 20k) then it doesn''t work either. The call is done to a web method and values are returned to list from a data set.

What I have tried:

source code:

<pre> <script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.js"></script>  
    <script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.js"></script>  
    <link rel="Stylesheet" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/themes/redmond/jquery-ui.css" /> 




$(document).ready(function(){

$(#txtSearch").autocomplete({

来源:功能(请求,响应){

$ .ajax({

类型:"POST",

contentType:"application/json; charset = utf-8",

网址:"Test.aspx/GetData",

数据:"{" DName:""+ document.getElementById(" txtSearch).value +"''},

dataType:"json",

成功:函数(数据){

response(data.d);

},

错误:函数(结果){

alert(错误......");

}

});

}

});

});



服务器端:




$(document).ready(function () {

$("#txtSearch").autocomplete({

source: function (request, response) {

$.ajax({

type: "POST",

contentType: "application/json; charset=utf-8",

url: "Test.aspx/GetData",

data: "{''DName'':''" + document.getElementById(''txtSearch'').value + "''}",

dataType: "json",

success: function (data) {

response(data.d);

},

error: function (result) {

alert("Error......");

}

});

}

});

});



server side:

string strInstList = string.Empty;

        List<string> result = new List<string>();

        //List<Corporate> result = new List<Corporate>();

        foreach (DataRow dr in DStEST.Tables[0].Rows)
        {
            result.Add(dr["CorporateID"].ToString());
        } 
return result;

推荐答案

(document).ready(function(){

(document).ready(function () {


(#txtSearch").autocomplete({

来源:功能(请求,响应){

("#txtSearch").autocomplete({

source: function (request, response) {


.ajax({

类型:"POST",

contentType:"application/json; charset = utf-8",

网址:"Test.aspx/GetData",

数据:"{" DName:""+ document.getElementById(" txtSearch).value +"''},

dataType:"json",

成功:函数(数据){

response(data.d);

},

错误:函数(结果){

alert(错误......");

}

});

}

});

});



服务器端:
.ajax({

type: "POST",

contentType: "application/json; charset=utf-8",

url: "Test.aspx/GetData",

data: "{''DName'':''" + document.getElementById(''txtSearch'').value + "''}",

dataType: "json",

success: function (data) {

response(data.d);

},

error: function (result) {

alert("Error......");

}

});

}

});

});



server side:
string strInstList = string.Empty;

        List<string> result = new List<string>();

        //List<Corporate> result = new List<Corporate>();

        foreach (DataRow dr in DStEST.Tables[0].Rows)
        {
            result.Add(dr["CorporateID"].ToString());
        } 
return result;


这篇关于如何为ASP.NET中的大量记录设置自动完成文本框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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