简体   繁体   English

从数据库中获取数据到自动完成文本框时出错

[英]Error when fetching data from database to autocomplete textbox

I have a form where i am using one autocomplete text box (using ajax autocomplete extender). 我有一个表单,其中我正在使用一个自动完成文本框(使用Ajax自动完成扩展程序)。
Autocomplete functionality is working properly. 自动完成功能正常运行。 But When I try to fetch data from database and try to display it in my form values doesn't display on form. 但是,当我尝试从数据库中获取数据并尝试以表单形式显示数据时,表单上没有显示。

As soon as I comment ajax autocomplete extender from page,all values gets displayed.Why is this happening? 一旦我从页面评论ajax自动完成扩展器,就会显示所有值。为什么会这样?

I need that autocomplete functionality in my form. 我需要表单中的自动完成功能。

<asp:TextBox ID="txtContactsSearch" runat="server" autopostback="True"></asp:TextBox>
<cc1:AutoCompleteExtender ServiceMethod="SearchCustomers"
MinimumPrefixLength="2"
CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
TargetControlID="txtContactsSearch"
ID="AutoCompleteExtender1" runat="server" FirstRowSelected = "false">
</cc1:AutoCompleteExtender>

public void getdata()
{
 Datatable dt=objdal.getdata();
 Datarow dr=dt=.Rows[0];
 txtContactsSearch.Text=dr["contact"].Tostring();
  //sililar code for remaining textboxes on form  
}

Ajax AutoComplete add Ajax AutoComplete添加

OnClientItemSelected="mycustomers" OnClientShowing="clientShowing OnClientItemSelected =“ mycustomers” OnClientShowing =“ clientShowing

     Call mycustomers() and clientShowing() in Javascript 

      Function mycustomers(){
      var str = $('#<%=txtname.ClientID %>').val();
       var partsOfStr = str.split(",");
        $.trim("partsOfStr");

      //spilt your string like this 
        $('#<%=txtname.ClientID %>').val(partsOfStr[0]);
        $('#<%=txtcontact.ClientID %>').val(partsOfStr[1]);


       }

       function clientShowing(source, args) {
        var popup = source._completionListElement;
        var height = popup.scrollHeight;
        var width = popup.scrollWidth;
        source._popupBehavior._element.style.height = "130px";
        source._popupBehavior._element.style.zIndex = 100000;
        //This iframe's height and width should be smaller than the CompletionList but bigger     than the DropDownList
        var iframe1 = "<IFRAME id='iframe1' style=' height:200px; width:10px; position:absolute; z-index:99999;border:0px; border-style:none; border-width:0px; ' ></IFRAME>";
        popup.innerHTML = iframe1 + popup.innerHTML;
    }

Call a webservice method in your .cs page 在.cs页面中调用Webservice方法

    [System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod (EnableSession=true)]


     public static List<string> SearchCustomers(string prefixText, int count)
     {
       sql = Select Name+ ',' + Contact+ ',' as Name From Table  where Name Like '%'+@Name+'%' 

       // Find the datatable or Dataset 

         // THEN add
        List<string> Contact= new List<string>();
        for (int i = 0; i < dt.Rows.Count; i++)
        {

            Company.Add(dt.Rows[i]["Name"].ToString());

        }
        return Contact;
    }
      }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM