为什么我的自动完成功能无效 [英] Why is my AutoComplete not working

查看:60
本文介绍了为什么我的自动完成功能无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



过去几天我一直在尝试自动完成工作。



我设法找到了一篇关于此的文章(http://www.codeproject.com/KB/aspnet/Autocomplete.aspx),我已经按照显示的所有步骤进行了操作但仍然无法正常工作。



我试图通过从mySQL创建的食物清单数据库表中获取食物来获得自动完成功能。



请告诉我是什么问题。



以下是代码。



谢谢。



Hello,

I have been trying to make my autocomplete work for the past few days.

I managed to find an article regarding this (http://www.codeproject.com/KB/aspnet/Autocomplete.aspx) and I have followed all the steps shown but still it is not working.

I am trying to get the autocomplete working by getting the food items from the food list database table which I have created in mySQL.

Please tell me what is the problem.

Below are the codes.

Thank you.

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetCompletionList(string prefixText, int count)
{
   SqlConnection cn = new SqlConnection();
   DataSet ds = new DataSet();
   DataTable dt = new DataTable();
   String strCn = "Data Source=MY-PC;Initial Catalog=SurveyDB;Integrated Security=True";
   cn.ConnectionString = strCn;
   SqlCommand cmd = new SqlCommand();
   cmd.Connection = cn;
   cmd.CommandType = CommandType.Text;

   cmd.CommandText = "SELECT * FROM FoodList WHERE Food like @Food";
   cmd.Parameters.AddWithValue("@Food", "%" + prefixText + "%");

   try
   {
      cn.Open();
      cmd.ExecuteNonQuery();
      SqlDataAdapter da = new SqlDataAdapter(cmd);
      da.Fill(ds);
   }
   catch
   {
   }
   finally
   {
      cn.Close();
   }
   dt = ds.Tables[0];

   List<string> txtItems = new List<string>();
   String dbValues;

   foreach (DataRow row in dt.Rows)
   {
      dbValues = row["Food"].ToString();
      dbValues = dbValues.ToLower();
      txtItems.Add(dbValues);
   }
   return txtItems.ToArray();
}



以下是设计师页面:


Below is the designer page:

<ajaxToolkit:AutoCompleteExtender

   ID="autoComplete1"  runat="server"

   EnableCaching="true"

   BehaviorID="AutoCompleteEx"

   MinimumPrefixLength="2"

   TargetControlID="TextBox1"

   ServicePath="AutoComplete.asmx"

   ServiceMethod="GetCompletionList"

   CompletionInterval="1000"

   CompletionSetCount="20"

                                    CompletionListCssClass="autocomplete_completionListElement"

   CompletionListItemCssClass="autocomplete_listItem"

                                    CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"

   DelimiterCharacters=";, :"

   ShowOnlyCurrentWordInCompletionListItem="true">
   <animations>
      <onshow>
      <sequence>
         <%-- Make the completion list transparent and then show it --%>
         <opacityaction opacity="0" />
         <hideaction visible="true" />

<%--Cache the original size of the completion list the first time the animation is played and then set it to zero --%>
         <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';
         }" />
         <%-- Expand from 0px to the appropriate size while fading in --%>
         <parallel duration=".4">
         <fadein />
         <length propertykey="height" startvalue="0">
            EndValueScript="$find('AutoCompleteEx')._height" />
         </length></parallel>
      </sequence>
      </onshow>
      <onhide>
         <%-- Collapse down to 0px and fade out --%>
         <parallel duration=".4">
            <fadeout />
            <length propertykey="height" startvaluescript="<br" mode="hold" />
            "$find('AutoCompleteEx')._height" EndValue="0" />
         </parallel>
       </onhide>
    </animations>
                                
    <asp:TextBox ID="TextBox1" runat="server" Width="275px">

推荐答案

find('AutoCompleteEx );
if(!behavior._height){
var target = behavior.get_completionList();
behavior._height = target.offsetHeight - 2;
target.style.height ='0px';
} / > ;
<% - 从0px扩展到适当的大小淡入 - %>
< parallel duration = 。4 >
< fadein / >
< length < span class =code-attribute> propertykey = height startvalue = 0 >
EndValueScript =
find('AutoCompleteEx'); if (!behavior._height) { var target = behavior.get_completionList(); behavior._height = target.offsetHeight - 2; target.style.height = '0px'; }" /> <%-- Expand from 0px to the appropriate size while fading in --%> <parallel duration=".4"> <fadein /> <length propertykey="height" startvalue="0"> EndValueScript="


find('AutoCompleteEx')._ height/>
< / length > < / parallel >
< / sequence >
< / onshow >
< 隐藏 > ;
<% - 折叠为0px 淡出 - - %>
< parallel 持续时间 = 。4 >
< fadeout / >
< length propertykey = height < span class =code-attribute> startvalue script = < br mode = hold / >
find('AutoCompleteEx')._height" /> </length></parallel> </sequence> </onshow> <onhide> <%-- Collapse down to 0px and fade out --%> <parallel duration=".4"> <fadeout /> <length propertykey="height" startvaluescript="<br" mode="hold" /> "


find('AutoCompleteEx')._ heightEndValue =0/>
< / parallel >
< / onhide >
< / animations >

< asp:TextBox ID = TextBox1 runat = server 宽度 = 2 75px >
find('AutoCompleteEx')._height" EndValue="0" /> </parallel> </onhide> </animations> <asp:TextBox ID="TextBox1" runat="server" Width="275px">


这篇关于为什么我的自动完成功能无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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