自动填充没有webservice的文本框 [英] Autocomplete textbox without webservice

查看:83
本文介绍了自动填充没有webservice的文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿伙计们,



我目前正在实现自动完成功能,而不使用网络服务,并将我的ServiceMethod属性作为GetProviders放在自动完成扩展程序中。



以下是xxx.aspx.cs中GetProviders方法的样子:

  public   static   string  [] GetProviders( string  prefixText, int  count)
{
ArrayList fd = new ArrayList();
fd.Add(DBManager.GetAllFood());
return fd;
}





我知道如何改进它?



提前谢谢

解决方案

我按照你的方式使用auto complete Extender ..这里拿看看代码:



aspx页面:



< asp:AutoCompleteExtender ID =   TextBox1_AutoCompleteExtender runat =   server 
CompletionInterval = 10 CompletionSetCount = 10 DelimiterCharacters =
Enabled = True FirstRowSelected = true MinimumPrefixLength = 1
Se rviceMethod = GetName TargetControlID = TextBox1 UseContextKey = true> ;





aspx.cs代码:



 [System.Web.Services.WebMethod] 
[System.Web.Script.Services.ScriptMethod]
public static List< string> GetName(string prefixText,int count)
{
if(count == 0)// count不应为零
{
count = 5;
}
SqlConnection conn = new SqlConnection();
conn.ConnectionString =< connectionstring> ;;
SqlCommand cmd = new SqlCommand(sqlquery,conn);
conn.Open();
List< string> names = new List< string>();
SqlDataReader dr = cmd.ExecuteReader();
while(dr.Read())
{
names.Add(dr [< columnname>]。ToString());
}
conn.Close();
返回姓名;
}< / columnname>< / connectionstring>





lemme知道这是不是您要找的。


Hey guys,

I am currently implementing an autocomplete feature without using a webservice, and have put my ServiceMethod attribute in the autocomplete extender as GetProviders.

Here's how the GetProviders method looks like in the xxx.aspx.cs:

public static string[] GetProviders(string prefixText, int count)
  {
      ArrayList fd = new ArrayList();
      fd.Add(DBManager.GetAllFood());
      return fd;
  }



Any idea how I can improve it??

Thanks in advance

解决方案

I use auto complete Extender just the way you do.. here take a look on code:

aspx page:

<asp:AutoCompleteExtender ID="TextBox1_AutoCompleteExtender" runat="server"
CompletionInterval="10" CompletionSetCount="10" DelimiterCharacters=""
Enabled="True" FirstRowSelected="true" MinimumPrefixLength="1"
ServiceMethod="GetName" TargetControlID="TextBox1" UseContextKey="true">



aspx.cs code:

[System.Web.Services.WebMethod]
    [System.Web.Script.Services.ScriptMethod]
    public static List<string> GetName(string prefixText, int count)
    {
        if (count == 0) //count should not be zero
        {
            count = 5;
        }
        SqlConnection conn = new SqlConnection();
        conn.ConnectionString = <connectionstring>;
        SqlCommand cmd = new SqlCommand(sqlquery, conn);
        conn.Open();
        List<string> names = new List<string>();
        SqlDataReader dr = cmd.ExecuteReader();
        while (dr.Read())
        {
            names.Add(dr[<columnname>].ToString());
        }
        conn.Close();
        return names;
    }</columnname></connectionstring>



lemme know if it was what you were looking for.


这篇关于自动填充没有webservice的文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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