Home > AJAX, ASP.Net > Display No Data Found with AJAX AutoComplete Extender

Display No Data Found with AJAX AutoComplete Extender

Hi all,

try this example to Display No Data Found Message with AJAX AutoComplete Extender

1) Open VS 2008 and create new web site

2) Add new web page and from Toolbox drag and drop ScriptManager , TextBox and AJAX AutoComplete Controls

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
 <style type="text/css">
 font-family: Arial;
 font-size: 10pt;
 margin: 0px !important;
 background-color: white;
 color: windowtext;
 border: buttonshadow;
 border-width: 1px;
 border-style: solid;
 cursor: 'default';
 overflow: auto;
 max-height: 200px;
 text-align: left;
 list-style-type: none;
 padding: 0px;
 <form id="form1" runat="server">
 <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
 <asp:TextBox ID="txtContactsSearch" runat="server"></asp:TextBox>
 <cc1:AutoCompleteExtender ServiceMethod="SearchCustomers" MinimumPrefixLength="2"
 CompletionInterval="100" EnableCaching="false" CompletionSetCount="10" TargetControlID="txtContactsSearch"
 ID="AutoCompleteExtender1" runat="server" FirstRowSelected="false" CompletionListCssClass="autocomplete_completionListElement"
 <script type="text/javascript">
 function OnClientItemSelected(sender, args) {
 var value = args.get_value();
 if (value == "No data found.") {
 $get("<%=txtContactsSearch.ClientID %>").value = "";

In code behind :

public static List<string> SearchCustomers(string prefixText, int count)
 using (SqlConnection conn = new SqlConnection())
 conn.ConnectionString = ConfigurationManager
 using (SqlCommand cmd = new SqlCommand())
 cmd.CommandText = "select ContactName from Customers where " +
 "ContactName like @SearchText + '%'";
 cmd.Parameters.AddWithValue("@SearchText", prefixText);
 cmd.Connection = conn;
 List<string> customers = new List<string>();
 using (SqlDataReader sdr = cmd.ExecuteReader())
 while (sdr.Read())
 if (customers.Count == 0)
 customers.Add("No data found.");
 return customers;

Hope this helps

Good Luck.

Categories: AJAX, ASP.Net
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: