ASPForums.Net RSS Feedhttp://www.aspforums.net/Handlers/RSS.ashxLatest additions to the content that appears on ASPForums.Net(c) 2019 www.aspforums.com. All rights reserved. jQuery AutoComplete TextBox using Microsoft Access Database in ASP.Net<p>Hi&nbsp;<a class="username" rel="ShihabKhan">ShihabKhan,</a></p> <h1 class="header"><a title="Clear jQuery AutoComplete TextBox when no match found'a" href="https://www.aspsnippets.com/Articles/Clear-jQuery-AutoComplete-TextBox-when-no-match-found.aspx">Clear jQuery AutoComplete TextBox when no match found</a></h1> <p>Refer below example.</p> <p><strong><span style="text-decoration: underline;">HTML</span></strong></p> <pre class="brush: html">&lt;script type=&#34;text/javascript&#34; src=&#34;http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.10.0.min.js&#34;&gt;&lt;/script&gt; &lt;script type=&#34;text/javascript&#34; src=&#34;http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/jquery-ui.min.js&#34;&gt;&lt;/script&gt; &lt;link rel=&#34;Stylesheet&#34; type=&#34;text/css&#34; href=&#34;http://ajax.aspnetcdn.com/ajax/jquery.ui/1.9.2/themes/blitzer/jquery-ui.css&#34; /&gt; &lt;script type=&#34;text/javascript&#34;&gt; $(function () { $(&#34;#txtSearch&#34;).autocomplete({ source: function (request, response) { $.ajax({ url: &#39;Default.aspx/GetFruits&#39;, data: &#34;{ &#39;prefix&#39;: &#39;&#34; + request.term + &#34;&#39;}&#34;, dataType: &#34;json&#34;, type: &#34;POST&#34;, contentType: &#34;application/json; charset=utf-8&#34;, success: function (data) { if (data.d.length &gt; 0) { response($.map(data.d, function (item) { return { label: item.Text, val: item.Value }; })) } else { response([{ label: &#39;No results found.&#39;, val: -1 }]); } } }); }, select: function (e, u) { if (u.item.val == -1) { $(this).val(&#34;&#34;); return false; } } }); }); &lt;/script&gt; Enter search term: &lt;input type=&#34;text&#34; id=&#34;txtSearch&#34; /&gt;</pre> <p><strong><span style="text-decoration: underline;">C#</span></strong></p> <pre class="brush: csharp">using System.Collections.Generic; using System.Data.OleDb; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { [System.Web.Services.WebMethod] [System.Web.Script.Services.ScriptMethod()] public static List&lt;ListItem&gt; GetFruits(string prefix) { List&lt;ListItem&gt; fruits = new List&lt;ListItem&gt;(); string str = &#34;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\\Fruit.accdb;Persist Security Info = False; &#34;; OleDbConnection con = new OleDbConnection(str); OleDbCommand cmd = new OleDbCommand(&#34;SELECT FruitId,FruitName FROM Fruits WHERE FruitName LIKE &#39;%&#39; + @Fruit + &#39;%&#39;&#34;, con); cmd.Parameters.AddWithValue(&#34;@Fruit&#34;, prefix); con.Open(); OleDbDataReader odr = cmd.ExecuteReader(); while (odr.Read()) { fruits.Add(new ListItem { Text = odr[&#34;FruitName&#34;].ToString().Trim(), Value = odr[&#34;FruitId&#34;].ToString().Trim() }); } con.Close(); return fruits; } }</pre> <p><strong><span style="text-decoration: underline;">VB.Net</span></strong></p> <pre class="brush: vb">Imports System.Collections.Generic Imports System.Data.OleDb Partial Class Default Inherits System.Web.UI.Page &lt;System.Web.Services.WebMethod()&gt; _ &lt;System.Web.Script.Services.ScriptMethod()&gt; _ Public Shared Function GetFruits(ByVal prefix As String) As List(Of ListItem) Dim fruits As List(Of ListItem) = New List(Of ListItem)() Dim str As String = &#34;Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Fruit.accdb;Persist Security Info = False; &#34; Dim con As OleDbConnection = New OleDbConnection(str) Dim cmd As OleDbCommand = New OleDbCommand(&#34;SELECT FruitId,FruitName FROM Fruits WHERE FruitName LIKE &#39;%&#39; + @Fruit + &#39;%&#39;&#34;, con) cmd.Parameters.AddWithValue(&#34;@Fruit&#34;, prefix) con.Open() Dim odr As OleDbDataReader = cmd.ExecuteReader() While odr.Read() fruits.Add(New ListItem With {.Text = odr(&#34;FruitName&#34;).ToString().Trim(), .Value = odr(&#34;FruitId&#34;).ToString().Trim()}) End While con.Close() Return fruits End Function End Class</pre> <p><strong><span style="text-decoration: underline;">Screenshot</span></strong></p> <p><strong><span style="text-decoration: underline;"><img src="https://www.aspsnippets.com/Handlers/DownloadFile.ashx?File=afa6c610-cc18-4194-9ba6-bf8e0c719f9f.gif" alt="" width="428" height="285" /></span></strong></p>https://www.aspforums.net:443/Threads/121846/jQuery-AutoComplete-TextBox-using-Microsoft-Access-Database-in-ASPNet/https://www.aspforums.net:443/Threads/121846/jQuery-AutoComplete-TextBox-using-Microsoft-Access-Database-in-ASPNet/Thu, 09 Aug 2018 09:18:48 GMT