2016-04-19 13 views
1

私はこのコードをaspsnippet.comから入手しました。テキストのオートコンプリートテキスト&イメージが機能しません。スクリプトは呼び出されません。 js関数が呼び出されると、どこにエラーがあるのか​​わかりますが、関数は呼び出されません。続いて、コード..asp.netのテキストと画像を含むテキストボックスをオートコンプリート

のaspx

<form id="form1" runat="server"> 
     <asp:ScriptManager ID="ScriptManager1" runat="server" 
      EnablePageMethods="true"> 
     </asp:ScriptManager> 
     <div> 
      <asp:TextBox ID="txtContactsSearch" runat="server"></asp:TextBox> 
      <cc1:AutoCompleteExtender ServiceMethod="SearchEmployees" 
       MinimumPrefixLength="1" 
       CompletionInterval="100" EnableCaching="false" CompletionSetCount="10" 
       TargetControlID="txtContactsSearch" OnClientPopulated="Employees_Populated" 
       OnClientItemSelected=" OnEmployeeSelected" 
       ID="AutoCompleteExtender1" runat="server" FirstRowSelected="false"> 
      </cc1:AutoCompleteExtender> 
     </div> 

     <script type="text/javascript"> 
      function Employees_Populated(sender, e) { 
       alert(Check2) 
       var employees = sender.get_completionList().childNodes; 
       for (var i = 0; i < employees.length; i++) { 
        var div = document.createElement("DIV"); 
        div.innerHTML = "<img style = 'height:50px;width:50px' src = 'list-business/assets/images/doctors/" 
        + employees[i]._value + ".jpg' /><br />"; 
        employees[i].appendChild(div); 
       } 
      } 
      function OnEmployeeSelected(source, eventArgs) { 
       alert(Check1) 
       var idx = source._selectIndex; 
       var employees = source.get_completionList().childNodes; 
       var value = employees[idx]._value; 
       var text = employees[idx].firstChild.nodeValue; 
       source.get_element().value = text; 
      } 
     </script> 
    </form> 

VB

Imports MySql.Data.MySqlClient 
Imports System.Collections.Generic 
Imports System.IO 

Partial Class _Default 
    Inherits System.Web.UI.Page 
    <System.Web.Script.Services.ScriptMethod(), 
    System.Web.Services.WebMethod()> 
    Public Shared Function SearchEmployees(ByVal prefixText As String, ByVal count As Integer) As List(Of String) 
     Dim conn As MySqlConnection = New MySqlConnection 
     conn.ConnectionString = ConfigurationManager _ 
     .ConnectionStrings("conio").ConnectionString 
     Dim cmd As MySqlCommand = New MySqlCommand 
     cmd.CommandText = "select doctorId, name, LastName from " & 
     " doctors where Name like @SearchText + '%'" 
     cmd.Parameters.AddWithValue("@SearchText", prefixText) 
     cmd.Connection = conn 
     conn.Open() 
     Dim employees As List(Of String) = New List(Of String) 
     Dim sdr As MySqlDataReader = cmd.ExecuteReader 
     While sdr.Read 
      employees.Add(AjaxControlToolkit.AutoCompleteExtender _ 
      .CreateAutoCompleteItem(String.Format("{0} {1}", 
      sdr("Name"), sdr("LastName")), sdr("doctorId").ToString())) 
     End While 
     conn.Close() 
     Return employees 
    End Function 
End Class 
+0

はその後、ウェブデバッグツールを使用して、あなたの 'alert'呼び出しの後ろにセミコロンを追加し、以下試してくださいですJavaScript?)を使用してJavaScriptエラーを探します。 – Alexander

答えて

1

Imports MySql.Data.MySqlClient 
Imports System.Collections.Generic 
Imports System.IO 

Partial Class _Default 
    Inherits System.Web.UI.Page 
    <System.Web.Script.Services.ScriptMethod(), 
    System.Web.Services.WebMethod()> 
    Public Shared Function SearchEmployees(ByVal prefixText As String, ByVal count As Integer) As List(Of String) 
     Dim conn As MySqlConnection = New MySqlConnection 
     conn.ConnectionString = ConfigurationManager _ 
     .ConnectionStrings("conio").ConnectionString 
     Dim cmd As MySqlCommand = New MySqlCommand 
     cmd.CommandText = "select doctorId, name, LastName from " & 
     " doctors where Name like '" + prefixText + "%'"    
     cmd.Connection = conn 
     conn.Open() 
     Dim employees As List(Of String) = New List(Of String) 
     Dim sdr As MySqlDataReader = cmd.ExecuteReader 
     While sdr.Read 
      employees.Add(AjaxControlToolkit.AutoCompleteExtender _ 
      .CreateAutoCompleteItem(String.Format("{0} {1}", 
      sdr("Name"), sdr("LastName")), sdr("doctorId").ToString())) 
     End While 
     conn.Close() 
     Return employees 
    End Function 
End Class 
関連する問題