Creating AutoComplete web service?

Last post 04-17-2007 3:14 PM by louisdegrazia. 6 replies.

Sort Posts:

  • Creating AutoComplete web service?

    04-16-2007, 12:56 PM
    • Member
      30 point Member
    • IgorV
    • Member since 04-04-2007, 12:43 PM
    • Posts 179

    Hello,

    I would just like to get some help on building a fairly simple webservice ( i would imagine it is simple) for my auto complete.  All i need is for the web service to have a list of my product names and each product name would have a link / redirect  to the product page once the client has inputed the full field or made the selection and clicked the search button.

     Can anyone help me out?  Novice here so i would really really appreciate it :).  Thank you!

  • Re: Creating AutoComplete web service?

    04-16-2007, 2:05 PM
    • Member
      186 point Member
    • ShepherdWeb
    • Member since 11-08-2006, 9:56 PM
    • Posts 75
    Hello IgorV—Since you've already downloaded and installed the AJAX Control Toolkit.  Open that directory and go to the SampleWebSite\AutoComplete\.  You will find a file called AutoComplete.asmx which provides a good example of what you are looking for.
    ★ ShepherdWeb
  • Re: Creating AutoComplete web service?

    04-16-2007, 2:46 PM
    • Member
      30 point Member
    • IgorV
    • Member since 04-04-2007, 12:43 PM
    • Posts 179
    Does anyone know of a VB.NET example?  The one thats in the sample site is C#.
  • Re: Creating AutoComplete web service?

    04-16-2007, 3:16 PM
    • Member
      186 point Member
    • ShepherdWeb
    • Member since 11-08-2006, 9:56 PM
    • Posts 75
    I don't know of a VB example, sorry.  However, I wouldn't think it'd be very hard to translate the example you have from C# to VB.  Have you considered this?
    ★ ShepherdWeb
  • Re: Creating AutoComplete web service?

    04-16-2007, 3:37 PM
    • Member
      30 point Member
    • IgorV
    • Member since 04-04-2007, 12:43 PM
    • Posts 179
    No i haven't because im a novice to VB so im sure it wouldnt work out lol.   But thank you.
  • Re: Creating AutoComplete web service?

    04-17-2007, 8:54 AM
    • Member
      186 point Member
    • ShepherdWeb
    • Member since 11-08-2006, 9:56 PM
    • Posts 75
    Ok, best of luck.
    ★ ShepherdWeb
  • Re: Creating AutoComplete web service?

    04-17-2007, 3:14 PM
    • Member
      526 point Member
    • louisdegrazia
    • Member since 02-15-2007, 10:41 AM
    • New Jersey
    • Posts 118

    Hello IgorV,

     

    I recently did this for AJAX using VB.Net. Here are the details to get you started:

    In the aspx page;

    <%

    @ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %>

    <%

    @ Import Namespace="System.Web.Services" %>

    <%

    @ Import Namespace="System.Data" %>

    <%

    @ Import Namespace="System.Data.SqlClient" %>

    <%

    @ Import Namespace="System.Collections.Generic" %>

    <%

    @ Import Namespace="System.Collections.Specialized" %>

    <

    script runat="server">

    <WebMethod()> _

    Public Shared Function GetSomeData(ByVal prefixText As String) As String()

    Dim cMyNames As New Collections.ArrayList

    Dim j As Integer

    j = 0

    Dim values(200) As String

    Dim conn As New System.Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ConnectionString)

    Dim cmd As SqlCommand

    Dim sCmdStr As String = ""

    cmd =

    New SqlCommand("MyProcedure", conn)

    cmd.CommandType = CommandType.StoredProcedure

    cmd.Parameters.Add(

    "@parm1", SqlDbType.VarChar).Value = prefixText

    conn.Open()

    Dim daNames As New System.Data.SqlClient.SqlDataAdapter(cmd)

    Dim dsNames As New System.Data.DataSet

    Dim dr As SqlDataReader = cmd.ExecuteReader()

    Try

    While dr.Read

    values(j) = dr(

    "MyColumn").ToString

    j = j + 1

    End While

    Catch ex As Exception

    Finally

    dr.Close()

    conn.Close()

    End Try

    Dim size As Integer = j

    size = size - 1

    Dim output(size) As String

    Dim k As Integer = 0

    While k < values.Length

    If size = -1 Then

    Exit While

    Else

    output(size) = values(k)

    size = size - 1

    End If

    k = k + 1

    End While

    Return output

    End Function

     

    </

    script>

    Then, in the content: 

    <

    asp:TextBox ID="TextBox1" runat="server" Width="71px" AutoComplete="off" ToolTip="This textbox will Auto Suggest" ></asp:TextBox>

    <ajaxToolkit:AutoCompleteExtender ID="AutoCompleteExtender2" runat="server"

    TargetControlID="TextBox1" ServiceMethod="GetSomeData" MinimumPrefixLength="2" EnableCaching="true"

    Enabled

    ="true" CompletionInterval="10" CompletionSetCount="5">

    </ajaxToolkit:AutoCompleteExtender>

    Hope this helps.

     

    Regards,

    Louis

Page 1 of 1 (7 items)