Autocompleteextender无法正常工作。请查看我的代码 [英] Autocompleteextender not working.Please check out my code

查看:91
本文介绍了Autocompleteextender无法正常工作。请查看我的代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我放在PRWebServics.cs中的web服务



Here is my webservice placed in PRWebServics.cs

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
 [System.Web.Script.Services.ScriptService]
public class PRWebService : System.Web.Services.WebService {
    public PRWebService () {

        //Uncomment the following line if using designed components 
        //InitializeComponent(); 
    }

    [System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod]
    public List<string> GetData(string DName)
    {

        List<string> result = new List<string>();

        using (SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["ProductReviewConnectionString"].ToString()))
        {
            using (SqlCommand cmd = new SqlCommand("select distinct Product_Name from Products where Product_Name like '%'+@SearchText+'%'", con))
            {

                con.Open();

                cmd.Parameters.AddWithValue("@SearchText", DName);

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataSet ds = new DataSet();
                da.Fill(ds);

                for (int i = 0;i < ds.Tables[0].Rows.Count; i++)
                {
                    result.Add(ds.Tables[0].Rows[i][0].ToString());
                }

                 return result;

            }

        }

    }



和我的html代码




and my in html code

<asp:ScriptManager ID="ScriptManager1" runat="server"

                           EnablePageMethods = "true">
                   </asp:ScriptManager>


                   <asp:TextBox ID="TxtSearch"  runat="server" AutoPostBack="true"

                       class="searchbox" MaxLength="255"

                   ></asp:TextBox>


                    <cc1:AutoCompleteExtender

                           MinimumPrefixLength="2"

                           CompletionInterval="1000"

                           EnableCaching="true"

                           CompletionSetCount="10"

                           TargetControlID="TxtSearch"

                           ID="AutoCompleteExtender1"

                           runat="server"

                           FirstRowSelected = "false"

                           ServiceMethod="GetData"

                           ServicePath="~/PRWebService.asmx"

                           CompletionListCssClass="autocomplete_completionListElement"

                           CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"

                           CompletionListItemCssClass="autocomplete_listItem"

                            >
                   </cc1:AutoCompleteExtender>

推荐答案

在您的方法中,参数应该只是 string prefixText 。 (我不知道为什么会这样,但确实如此。我也在努力。))

将你的参数名改为。



-KR
Well in your method the parameter should be string prefixText only. (I don't have any idea why is it so, but it is. I was also struggling with that. ;))
Change your parameter name to that.

-KR


这篇关于Autocompleteextender无法正常工作。请查看我的代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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