2014-09-25 111 views
0

我有一個表單,我使用的是一個自動填充文本框(使用ajax自動填充擴展器)。
自動完成功能正常運行。但是,當我嘗試從數據庫中獲取數據並嘗試在我的表單中顯示它時,它不會在窗體上顯示。從數據庫中提取數據到自動填充文本框時出錯

只要我從頁面評論ajax自動完成擴展器,所有值都會顯示。爲什麼會發生這種情況?

我需要我的表單中的自動完成功能。

<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 
} 
+1

任何代碼webservice的方法是什麼?我不能猜你怎麼實現它 – 2014-09-25 07:01:14

+1

你什麼時候調用'getdata()'?我的意思是哪個事件 – Shaharyar 2014-09-25 07:21:32

+0

在我的表單中的另一個文本框的textchanged事件 – user3024200 2014-09-25 07:25:31

回答

0

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頁

[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 '%'[email protected]+'%' 

     // 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; 
    } 
     }