ajaxtoolkit自动完成不起作用

ajaxtoolkit自动完成不起作用

我尝试使用AutoCompleteExtender,但无法正常工作。我使用ajaxToolkit和Web服务文件。两者都没有错误。我认为脚本可能是错误的,请给我一些修复建议。

< 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>


AutoComplete.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/

10-09 19:22