c# - asp.net ajaxtoolkit 自动完成功能不起作用

标签 c# asp.net web-services autocomplete

我尝试使用 AutoCompleteExtender,但它不起作用。我使用 ajaxToolkit 和网络服务文件。他们两个都没有错误。我认为脚本可能是错误的请给我建议修复。

< ajaxToolkit:AutoCompleteExtender
                           runat="server" 
                            BehaviorID="AutoCompleteEx"
                            ID="autoComplete1" 
                            TargetControlID="TextBox"
                            ServicePath="AutoComplete.asmx" 
                            ServiceMethod="GetCompletionList"
                            MinimumPrefixLength="2" 
                            CompletionInterval="1000"
                            EnableCaching="true"
                            CompletionSetCount="20"
                            CompletionListCssClass="autocomplete_completionListElement" 
                            CompletionListItemCssClass="autocomplete_listItem" 
                            CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
                            DelimiterCharacters=";, :"
                             OnClientShowing="true" >
                                  <Animations>
                                <OnShow>
                                    <Sequence>

                                        <OpacityAction Opacity="0" />
                                        <HideAction Visible="true" />


                                        <ScriptAction Script="
                                            // Cache the size and setup the initial size
                                            var behavior = $find('AutoCompleteEx');
                                            if (!behavior._height) {
                                                var target = behavior.get_completionList();
                                                behavior._height = target.offsetHeight - 2;
                                                target.style.height = '0px';
                                            }" />


                                        <Parallel Duration=".4">
                                            <FadeIn />
                                            <Length PropertyKey="height" StartValue="0" EndValueScript="$find('AutoCompleteEx')._height" />
                                        </Parallel>
                                    </Sequence>
                                </OnShow>
                                <OnHide>

                                    <Parallel Duration=".4">
                                        <FadeOut />
                                        <Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" />
                                    </Parallel>
                                </OnHide>
                            </Animations>
                            </ajaxToolkit:AutoCompleteExtender>

自动完成.asmx:

 public string[] GetCompletionList(string prefixText, int count)
    {


        SqlConnection cn = new  SqlConnection(ConfigurationManager.AppSettings["U"].ToString());
        DataSet ds = new DataSet();
        DataTable dt = new DataTable();

        SqlCommand cmd = new SqlCommand();
        cmd.Connection = cn;
        cmd.CommandType = CommandType.Text;

        cmd.CommandText = "select * from Stoc  WITH (NOLOCK) where  KeySentences like @myParameter";
        cmd.Parameters.AddWithValue("@myParameter", "%" + prefixText + "%");
        try
        {
            cn.Open();
            cmd.ExecuteNonQuery();
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            da.Fill(ds);
        }
        catch (Exception ex)
        {

        }
        finally
        {
            cn.Close();
        }
        dt = ds.Tables[0];

        //Then return List of string(txtItems) as result
        List<string> txtItems = new List<string>();
        String dbValues;

        foreach (DataRow row in dt.Rows)
        {
            //String From DataBase(dbValues)
            dbValues = row["KeySentences"].ToString();
            dbValues = dbValues.ToLower();
            txtItems.Add(dbValues);

        }

        return txtItems.ToArray();

    }

感谢您的回答..

最佳答案

我用我的 ajaxtoolkit4.5 错误测试这个属性。

OnClientShowing="true"

不确定您想做什么,但请帮我删除这项工作。 (我通过删除数据库连接和工作来复制你的代码)

关于c# - asp.net ajaxtoolkit 自动完成功能不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16895941/

相关文章:

asp.net - Request.ServerVariables ("LOGON_USER")VS2010 和 VS2012

Asp.Net MVC - 重载操作方法

c# - 提交方法无法识别 AddWithValue

c# - 使用 SSL 的 .net Web 服务。 wcf?

c# - 在 catch block 中继续

c# - 为什么发送到 POST 的类对象为 NULL?

c# - 无法确定类型为 “System.Data.Sqlite.SqliteFactory” 的提供程序工厂的提供程序名称

c# - gzipstream 用于套接字上的仅转发流

amazon-web-services - 使用 AWS CDK 配置 Lambda 加热器

java - 如何使用 BasicHttpBinding 和 BasicHttpSecurityMode.TransportWithCredential : 将 header 元素 "mustunderstand=0"设置到 SOAP 请求中