ASP.NET vb.net TextBox avec JQuery AutoComplete

Signaler
Messages postés
3
Date d'inscription
lundi 4 mai 2020
Statut
Membre
Dernière intervention
6 mai 2020
-
Bonjour.
Je tente de créer un textbox autocompleted avec jquery. J'ai lu toutes les documentations. J'implémente et quand j'exécute, il ne trouve pas de résultat. Voici le code

asp.net

<asp:TextBox ID="txtEssai" runat="server"></asp:TextBox>


Javascript

<script src="http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.js"></script>  
<script src="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.22/jquery-ui.js"></script> 
<link rel="Stylesheet" href="http://ajax.aspnetcdn.com/ajax/jquery.ui/1.8.10/themes/redmond/jquery-ui.css"/>  
 
<script type="text/javascript">
        $(document).ready(function () {
            SearchText();
        });
        function SearchText() {
            $("#txtEssai").autocomplete({
                source: function (request, response) {
                    var param = { bMarqueModele: $('#txtEssai').val() };
                    $.ajax({
                        url: "login.aspx/ListeMarqueModele",
                        data: JSON.stringify(param),
                        dataType: "json",
                        type: "POST",
                        contentType: "application/json; charset=utf-8",
                        data: "{'bMarqueModele':'" + document.getElementById('txtEssai').value + "'}",
                        dataFilter: function (data) { return data; }, 
                        success: function (data) {
                            response($.map(data.d, function (item) {  
                                return {  
                                    value: item
                                }
                            }))
                        },
                        error: function (result) {
                            alert("No Match");
                        }
                    });
                }
            });
        }
</script>


Vb.net

Imports System.Data.SqlClient
Imports System.Web.Services
 
Public Class login
    <WebMethod()>
    Public Function ListeMarqueModele(ByVal bMarqueModele As String) As List(Of String)
        Dim Result As List(Of String) = New List(Of String)
        ExecuteLMD("select MarqueModele from a_vehicule where (MarqueModele like '" & bMarqueModele & "%')")
        Dim rn As Integer
 
        Do Until rn > bTab.Rows.Count - 1
            Result.Add(bTab.Rows(rn).Item(0).ToString)
            rn = rn + 1
        Loop
 
        bTab = Nothing
        Return Result
    End Function
 
    Dim bTab As DataTable
 
    Private Sub ExecuteLMD(ByVal bSql As String)
        Dim sqlCmd As New SqlCommand(bSql)
        Dim Dadpter As New SqlDataAdapter(sqlCmd)
        bTab = New DataTable
        Dim Dset As New DataSet
        SqlConn.Open()
        sqlCmd.Connection = SqlConn
        Dadpter.Fill(Dset, "bTable")
        bTab = Dset.Tables("bTable")
 
        sqlCmd = Nothing
        Dadpter = Nothing
        Dset = Nothing
        SqlConn.Close()
    End Sub
 
    Dim SqlConn as SqlConnection
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SqlConn = New SqlConnection
        SqlConn.ConnectionString = ConfigurationManager.ConnectionStrings("LGHI").ToString
    end sub
end class


Quand j'exécute, il me ramène le message 'No match'. Où est ce que j'ai fait la faute?