|
Forums » .NET » ASP.NET »
|
Regarding textbox's auto complete propertie. |
Posted Date: 08 Sep 2012 Posted By:: parth Member Level: Silver Member Rank: 911 Points: 2
Responses:
8
|
i had created one website in ASP .NET C#. In one page i put one textbox with watermark effect with help of ajax. That text box is use for Search purpose , Now i want that if any body write some words on that textbox , it will display whole words like google does. so how can i do that?
|
Responses
|
#688039 Author: Pawan Awasthi Member Level: Diamond Member Rank: 4 Date: 08/Sep/2012 Rating:  Points: 4 | Hai Parth, TextBox AutoComplete is an ASP.NET AJAX extender which comes with the Ajax Toolkit. We can attach this ASP.NET AJAX extender to the controls like TextBox and when the user will type the strating letter, it will show the related words in form of drpdown list so that user can choose the word as per their requirements. To use this feature of Ajax ToolKit, you need to first download the AjaxToolkit and then you can use the AutoComplete externdar as: 1. Register the AjaxToolkit into your page. 2. Attach the textbox with AutoComplete externdar
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="mac" %> <form id="form1" runat="server"> <asp:ScriptManager ID="ScriptManager1" runat="server" /> <div> <asp:TextBox ID="txtAutoTextSearch" runat="server"></asp:TextBox> <mac:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" ServicePath="MyService.asmx" ServiceMethod="FindRelatedWords" MinimumPrefixLength="1" TargetControlID="txtAutoTextSearch"> </mac:AutoCompleteExtender> </div> </form>
Here the Myservice.asmx is the webservice to find the related words based on the keyword user will type in the textbox. FindRelatedWordse is the webmethod to find the related words. Hope it will be helpful to you.
Regards, Pawan Awasthi(DNS MVM) +91 8143683708 (pawansoftit@gmail.com) Outstanding Contribution Award..NTT Data Inc
| #688044 Author: Gopi A Member Level: Silver Member Rank: 349 Date: 08/Sep/2012 Rating:  Points: 4 | Hi,
We can achieve this using AJAX tool kit along with ASP.net Web Service concept.
AutoComplete is an ASP.NET AJAX extender that can be attached to any TextBox control, and will associate that control with a popup panel to display words that begin with the prefix typed into the textbox.
<ajaxToolkit:AutoCompleteExtender runat="server" ID="autoComplete1" TargetControlID="myTextBox" ServiceMethod="GetCompletionList" ServicePath="AutoComplete.asmx" MinimumPrefixLength="2" CompletionInterval="1000" EnableCaching="true" CompletionSetCount="20" CompletionListCssClass="autocomplete_completionListElement" CompletionListItemCssClass="autocomplete_listItem" CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem" DelimiterCharacters=";, :" ShowOnlyCurrentWordInCompletionListItem="true"> <Animations> <OnShow> ... </OnShow> <OnHide> ... </OnHide> </Animations> </ajaxToolkit:AutoCompleteExtender>
For more details refer the below.
Using AJAX
http://www.asp.net/ajaxlibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx
Using JQuery.
http://www.dotnetcurry.com/ShowArticle.aspx?ID=515
----------------------------------------------------------------------------- Regards, Gopi A. +91 9894315571 Skype:gopi.net
| #688048 Author: Ravindran Member Level: Diamond Member Rank: 3 Date: 09/Sep/2012 Rating:  Points: 4 | Hi,
Refer below code sample i have load all country name in the database table and suggest text when user press first few letters.
WebService.cs
[WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Script.Services.ScriptService] public class WebService : System.Web.Services.WebService { public WebService() { }
[WebMethod] public string[] GetCountry(string prefixText) { //Retieve connection string from config file and assigned in to the sqlconnection SqlConnection sqlcon = new SqlConnection(ConfigurationManager.ConnectionStrings["Con"].ConnectionString); SqlCommand sqlcmd = new SqlCommand(); DataSet ds = new DataSet(); //write query to get country name based on user entered text string query = "select country from cntryname where country like '" + prefixText + "%' "; sqlcmd = new SqlCommand(query, sqlcon); sqlcon.Open(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = sqlcmd; da.Fill(ds); //Create one array variable and set size based on return datatable row count string[] cname = new string[ds.Tables[0].Rows.Count]; int i = 0; try { foreach (DataRow dr in ds.Tables[0].Rows) { //assign each value in to the array variable cname.SetValue(dr["country"].ToString(), i); i++; } } catch (Exception ex) { } finally { sqlcon.Close(); } //Lastreturn that array values for bind in extender return cname; } }
In the .aspx page i have load using below code
<html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>AJAX Auto Complete Extender</title> <style> .Extender { font-family: Verdana, Helvetica, sans-serif; font-size: 10px; font-weight: normal; border: solid 1px #006699; line-height: 20px; padding: 1px; background-color: White; } .ExtenderList { border-bottom: 1px #006699; cursor: pointer; color: black; } .Highlight { color: White; background-color: #229603; cursor: pointer; } #width { width: 180px; } </style> </head> <body> <form id="form1" runat="server"> <div> <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server"> <Services> <asp:ServiceReference Path="WebService.asmx" /> </Services> </asp:ToolkitScriptManager> Enter Country Name <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <asp:AutoCompleteExtender runat="server" ID="autoComplete1" TargetControlID="TextBox1" MinimumPrefixLength="1" EnableCaching="true" CompletionListCssClass="Extender" CompletionListItemCssClass="ExtenderList" CompletionListHighlightedItemCssClass="Highlight" CompletionListElementID="width" /> </div> </form> </body> </html>
Further more in detail refer my resource http://www.dotnetspider.com/resources/43207-How-create-auto-complete-extender-with-use.aspx
Regards N.Ravindran Your Hard work never fails
| #688051 Author: parth Member Level: Silver Member Rank: 911 Date: 09/Sep/2012 Rating:  Points: 1 | Hello ravindra thanks for your reply. but hou to add WebService.asmx. and when i run this it shows error like 1) "The type or namespace name 'WebMethod' could not be found (are you missing a using directive or an assembly reference?)"
| #688052 Author: parth Member Level: Silver Member Rank: 911 Date: 09/Sep/2012 Rating:  Points: 1 | @ Ravindran .. i have solved error but cant show any result.. help me with that
| #688056 Author: Ravindran Member Level: Diamond Member Rank: 3 Date: 09/Sep/2012 Rating:  Points: 2 | Parth,
Your webmethod name is not available in your code mean that web service and make sure you added table name /field are correct and also put breakpoint in service method to check whether get data from table or not.
Regards N.Ravindran Your Hard work never fails
| #688097 Author: Anil Kumar Pandey Member Level: Platinum Member Rank: 1 Date: 09/Sep/2012 Rating:  Points: 2 | You can try using the Ajax Auto Complete extender control. here is a syntax for the same.
<div ID="divwidth"> <ajaxToolkit:AutoCompleteExtender runat="server" ID="AutoCompleteExtender1" BehaviorID="autoComplete" TargetControlID="txtAutoComplete" ServicePath="AutoComplete.asmx" ServiceMethod="GetCompletionList" MinimumPrefixLength="1" CompletionInterval="10" EnableCaching="true" CompletionSetCount="12" CompletionListCssClass="AutoExtenderCSS" CompletionListItemCssClass="AutoExtenderList" CompletionListHighlightedItemCssClass ="AutoExtenderHighlight" CompletionListElementID="divwidth"> <ajaxToolkit:AutoCompleteExtender>
</div>
Thanks & Regards Anil Kumar Pandey Microsoft MVP, DNS MVM
| #688255 Author: parth Member Level: Silver Member Rank: 911 Date: 10/Sep/2012 Rating:  Points: 1 | @Ravindran can you please give example of 3 deep level of tree view??
|
|
| Post Reply |
|
|
|
You must Sign In to post a response.
|
|
|
|
 Follow us on Twitter: https://twitter.com/dotnetspider
|
|