Blue Theme Orange Theme Green Theme Red Theme
 
Click Here for 3 Month Free of ASP.NET Hosting!
Home | Forums | Videos | Photos | Downloads | Blogs | E-Books | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
Search :       Advanced Search »
Home » Blogs Home » Blog Detail
AutoComplete TextBox from DataBase
 by Arumugam A on Nov 04, 2009

Autocomplete prompt from database for textbox using ajax autocomplete extender
Comments: 0 Views: 619     Printable Version

In order to use the ajax autocomplete extender we have to use an asp.net

component i.e. Webservice.asmx

This component is used to be get connect with the database.

we can get this component simply by right click on asp.net project and add new item.

By doing so an .cs file will be generated named Webservice.cs in App_Code folder.

We have to add the following webmethod in the cs class file.


public string[] GetLocationInfo(string prefixText)
{
 int count = 10;
 string sql = "Select * from Locations Where Location like @prefixText";
 SqlDataAdapter da = new SqlDataAdapter(sql,webindia.Connstring);
 da.SelectCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText+ "%";
 DataTable dt = new DataTable();
 da.Fill(dt);
 string[] items = new string[dt.Rows.Count];
 int i = 0;
 foreach (DataRow dr in dt.Rows)
 {
  items.SetValue(dr["Location"].ToString(),i);
  i++;
 }
 return items;
}



// To allow this Web Service to be called from script, using ASP.NET AJAX,we have to add the below namespace outside the class on starting itself
 [System.Web.Script.Services.ScriptService]




In the design side we have to do the following:


<asp:TextBox Maxlength="50" id="txtname2" class="bdtxt" onblur="this.value=Trim(this.value)" onkeypress="return noNumbers(event)" runat="server"/>


 <cc1:AutoCompleteExtender CompletionListCssClass="Completer_completionListElement FS-NBK" CompletionListItemCssClass="Completer_listItem" CompletionListHighlightedItemCssClass="Completer_highlightedListItem" ID="AutoCompleteExtender1" runat="server" MinimumPrefixLength="1" ShowOnlyCurrentWordInCompletionListItem="true" ServiceMethod="GetLocationInfo" FirstRowSelected="true"  ServicePath="WebService.asmx" TargetControlID="txtname2"> </cc1:AutoCompleteExtender>
                   


And then run the project, it will work effectively




*Title:  
*Comment:
 
 
No record available

 Blogger's Profile
Age: Not Available
Location:
Title: Developer
Joined: Nov 04, 2009
Education: Bachelors Degree
 More Blogs from this Blogger
Ajax Modal Popup Extender
AutoComplete TextBox from DataBase
View all »
 Latest Blogs
RadEditor in asp.net using Telerik Controls Dll
deleting the duplicate records from SQL Server table
how can i change Text to Graphics
play flash files in windows forms using c#
convert the database table into xml
Autocomplete Textbox im asp.net
SQL Server 2008 installation problem
pictures
Visual Studio 2010 - Installation Problems Discuss
Reporting Services Catalog Error
View all »
 Latest Articles
Pie Chart in WPF
Creating a Line Chart Application in GDI+
DOM Overview
Control Statements in C#
Cursors in Silverlight 3
Hyperlink Text Wrap In Silverlight 3
Literal Control in ASP.NET
Bar Chart in WPF
An XML Document and its Items
Drawing Ellipses and Circles in GDI+
View all »

 Hosted by MaximumASP  |  Found a broken link?  |  Contact Us  |  Terms & conditions  |  Privacy Policy  |  Site Map  |  Suggest an Idea  |  Media Kit
Current Version: 5.2009.6.2
 © 1999 - 2009  Mindcracker LLC. All Rights Reserved