Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/284.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/visual-studio/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将数据从数据库提取到自动完成文本框时出错_C#_Asp.net - Fatal编程技术网

C# 将数据从数据库提取到自动完成文本框时出错

C# 将数据从数据库提取到自动完成文本框时出错,c#,asp.net,C#,Asp.net,我有一个表单,其中我使用一个使用ajax autocomplete extender的自动完成文本框。 自动完成功能工作正常。但当我尝试从数据库中获取数据并尝试在表单中显示数据时,值不会显示在表单上 当我在页面上评论ajax autocomplete extender时,所有的值都会显示出来。为什么会发生这种情况 我需要在我的表单中使用自动完成功能 <asp:TextBox ID="txtContactsSearch" runat="server" autopostback="True"&

我有一个表单,其中我使用一个使用ajax autocomplete extender的自动完成文本框。 自动完成功能工作正常。但当我尝试从数据库中获取数据并尝试在表单中显示数据时,值不会显示在表单上

当我在页面上评论ajax autocomplete extender时,所有的值都会显示出来。为什么会发生这种情况

我需要在我的表单中使用自动完成功能

<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自动完成添加

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;
    }
在.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;
    }
      }

有密码吗?我猜不出你是如何实现它的。你什么时候调用getdata?我的意思是,在哪个事件上,文本更改了我表单中另一个文本框的事件,它允许自动回发?这不在任何更新面板中吗?是的,它允许回发。整个表单都在更新面板中。