关于autocomplete控件在ASP.NET中的问题
现在实现这样一个要求:使用autocomplete扩展控件,当用户输入的时候自动到数据库中查找匹配的选项。这样会有一个性能的问题,大家知道,对数据库进行连接是比较耗时的,我想定义一个dataview的全局变量,在page_load函数里讲数据库的内容先做在dataview里,然后在autocomplete输入的时候从dataview里面查找匹配的内容,这样速度应该会快一些,不过实践中发现在autocomplete的GetCompletionList函数中并不能访问先前定义的dataview全局变量,大家有什么好办法能够解决呢?
代码例子:
public partial class Machine : System.Web.UI.Page
{
dataview dataview1 = new dataview(); //这里定义全局变量dataview1
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
//在这里连接数据库,并将数据库里的内容检索出来放入全局变量dataview1 或者datatable;
}
}
[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string[] GetCompletionList(string prefixText, int count, string contextKey)
{
//想在这里访问dataview1的内容,编译器不让访问,有什么办法呢?
return default(string[]);
}
}