<System.Web.Script.Services.ScriptMethod(), _ System.Web.Services.WebMethod()> _ Public Shared Function SearchDepartement(ByVal prefixText As String, ByVal count As Integer) As List(Of String) Try Dim conn As SqlConnection = New SqlConnection conn.ConnectionString = ConfigurationManager _ .ConnectionStrings("ficogesconn").ConnectionString Dim cmd As SqlCommand = New SqlCommand cmd.CommandText = "select Libelle from Departement where" & _ " Libelle like @SearchText + '%'" cmd.Parameters.AddWithValue("@SearchText", prefixText) cmd.Connection = conn conn.Open() Dim departements As List(Of String) = New List(Of String) Dim sdr As SqlDataReader = cmd.ExecuteReader While sdr.Read departements.Add(sdr("Libelle").ToString) End While conn.Close() Return departements Catch ex As Exception
You can bind the textbox with onchange event and send an ajax request to server which will bring the list of data based on input and show an ui below the textbox.
see the below example-
onchange="GetItemDetails(this);"
$.post(url, { id: data }, function (response) {
//here bind data to the dropdown
})
you can also use the various jquery autocomplete library.
Share the code, might be the value you passing at the time of autocomplete, not getting passed or might be some other reason, you have to share the code you used for this.
Bikesh SrivastavaPosted Sep 28, 2016, 11:28 PM
diane moussaPosted Sep 28, 2016, 11:28 AM
<asp:TextBox ID="txtdepartementadd" runat="server" class="form-control col-md-6">
</asp:TextBox>
<cc1:AutoCompleteExtender ServiceMethod="SearchDepartement"
MinimumPrefixLength="2"
CompletionInterval="100" EnableCaching="false" CompletionSetCount="10"
TargetControlID="txtdepartementadd"
ID="AutoCompleteExtender1" runat="server" FirstRowSelected ="false">
</cc1:AutoCompleteExtender>
</td>
System.Web.Services.WebMethod()> _
Public Shared Function SearchDepartement(ByVal prefixText As String, ByVal count As Integer) As List(Of String)
Try
Dim conn As SqlConnection = New SqlConnection
conn.ConnectionString = ConfigurationManager _
.ConnectionStrings("ficogesconn").ConnectionString
Dim cmd As SqlCommand = New SqlCommand
cmd.CommandText = "select Libelle from Departement where" & _
" Libelle like @SearchText + '%'"
cmd.Parameters.AddWithValue("@SearchText", prefixText)
cmd.Connection = conn
conn.Open()
Dim departements As List(Of String) = New List(Of String)
Dim sdr As SqlDataReader = cmd.ExecuteReader
While sdr.Read
departements.Add(sdr("Libelle").ToString)
End While
conn.Close()
Return departements
Catch ex As Exception
End Try
End Function
Midhun TpPosted Sep 28, 2016, 9:45 AM
I think you are using ajax concept for autocomplete. In your ajax page, remove all codes from aspx page. That is doctype, html tag, head tag, etc...
Ujjwal GuptaPosted Sep 28, 2016, 9:07 AM
Anil ThakurPosted Sep 28, 2016, 9:00 AM
Bhushan BhasmePosted Sep 28, 2016, 8:57 AM