AutocompleteExtender

Posted by Dipakagarwal under ASP.NET on 6/14/2012 | Points: 10 | Views : 2159 | Status : [Member] | Replies : 6
Hi Dipak is here,
i want to use a textbox which work like a autocomplete using autocompleteExtender , and it take values from webservice, please let me know code for code behind and webservice code to implement this feature.................

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>

<asp:TextBox ID="txtFind" runat="server" ></asp:TextBox>
<cc1:AutoCompleteExtender
runat="server"
ID="autoComplete1"
TargetControlID="txtFind"
ServiceMethod="search"
ServicePath="http://ircig/_layouts/IRCIG/ircigautocomplete.asmx"
MinimumPrefixLength="0"
CompletionInterval="100"
EnableCaching="true">
</cc1:AutoCompleteExtender>

and i have also added dll with correct version...
but autocomplete is not working..




Responses

Posted by: Jeena on: 6/15/2012 [Member] Starter | Points: 25

Up
0
Down
Hi deepak,

http://www.asp.net/ajaxLibrary/AjaxControlToolkitSampleSite/AutoComplete/AutoComplete.aspx
http://www.aspdotnetcodes.com/AutoComplete_From_Database.aspx


I believe this links will help you to achieve it

Thanks,
Jeena



Dipakagarwal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dipakagarwal on: 6/21/2012 [Member] Starter | Points: 25

Up
0
Down
hi jeena thanx, i already tried it...

Dipakagarwal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Johnbhatt on: 6/21/2012 [Member] Starter | Points: 25

Up
0
Down
Dear Deepak,

This can be code behind aspx page. Here I am going to Directly code in same page instead of using any service, which will be more faster and reliable also.

Place a Textbox in aspx page and apply ajax autoextender. Then change Webmethod name, which is GetvehicleList in case of below code. So your code for textbox and with Extender will look like as below:
<asp:TextBox ID="txtVehicleNo" runat="server" ToolTip="Enter Vehicle Number (Full)"

Width="168px"></asp:TextBox>
<asp:AutoCompleteExtender ID="txtVehicleNo_AutoCompleteExtender" runat="server" DelimiterCharacters=""
Enabled="True" ServiceMethod="GetVehicleList" ServicePath="" TargetControlID="txtVehicleNo"
UseContextKey="True" MinimumPrefixLength="2">
</asp:AutoCompleteExtender>


Code in aspx.cs page

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]

public static string[] GetVehicleList(string prefixText, int count, string contextKey)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConToJohnB"].ConnectionString);
SqlDataAdapter adp = new SqlDataAdapter("Select distinct VehicleNo from VehicleDispatch where VehicleNo like '%" + prefixText + "%'", con);
DataSet ds = new DataSet();
adp.Fill(ds, "Vehicles");
string[] VehicleNo = new string[ds.Tables["Vehicles"].Rows.Count];
for (int i = 0; i <= ds.Tables["Vehicles"].Rows.Count - 1; i++)
{
VehicleNo.SetValue(ds.Tables["Vehicles"].Rows[0][0].ToString(), i);
}
return VehicleNo;
}


In case of any confusion in above code, you can revert.

John Bhatt
Glad to Know, Free to Share.....
http://www.johnbhatt.com

Dipakagarwal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Dipakagarwal on: 6/22/2012 [Member] Starter | Points: 25

Up
0
Down
Hi Johnbhatt,
thanks a lot to reply to AutoCompleteExtender probelm, actually i am not using sql, i am trying to give static data in webservice and accessing it..
its working very fine in my local system but when i am putting the same code to sever, AutoCompleteExtender is not working...

AutoComplete.aspx

<body>
<form id="form1" runat="server">
<asp:ScriptManager id="ScriptManager1" runat="server" EnablepageMethods="true">
</asp:ScriptManager>
<div>
<asp:TextBox ID="txtAuto" runat="server"></asp:TextBox>
<cc1:AutoCompleteExtender
runat="server"
ID="autoComplete1"
TargetControlID="txtAuto"
ServiceMethod="search1"
ServicePath="~/WebService_Auto.asmx"
MinimumPrefixLength="1"
CompletionInterval="100"
EnableCaching="true"
ShowOnlyCurrentWordInCompletionListItem="true">
</cc1:AutoCompleteExtender>
</div>
</form>
</body>

WebMethod in WebService_Auto

<WebMethod()> _
Public Function search1(ByVal prefixText As String) As String()
Dim arr As String() = New String() {"abc", "def", "hij", "ab", "de", "hi", "ac", "df", "hj", "bc", "def", "hij"}
Dim y = (From _ar As String In arr Where _ar.ToLower.StartsWith(prefixText.ToLower) Select _ar)
Return y.ToArray()
End Function

you plz see it, its working fine in my local but not in server...

Dipakagarwal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ajay.Kalol on: 6/22/2012 [Member] Starter | Points: 25

Up
0
Down
http://ajaypatelfromsanthal.blogspot.in/2012/06/normal-0-false-false-false-en-us-x-none.html


refer this link for simple Solution

Ajay
ajaypatelfromsanthal.blogspot.in

Dipakagarwal, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 7/9/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Plz refer this link

http://www.codeproject.com/Articles/259376/Using-Ajax-AutoCompleteExtender-for-autosuggest

Dipakagarwal, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response