Hi Can anybody help us, why the below code is not working, when im entering some product name in the text box.. any help appreciated.. thanksautocomplete.asmx
Imports System
Imports System.Collections
Imports System.Linq
Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Xml.Linq
Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient<WebService(Namespace:="http://tempuri.org/")> _<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _<System.Web.Script.Services.ScriptService()> _<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Public Class AutoComplete
Inherits System.Web.Services.WebService
Dim cn As New SqlClient.SqlConnection()
Dim ds As New DataSet
Dim dt As New DataTable<WebMethod()> _
Public Function GetCompletionList(ByVal prefixText As String, _
ByVal count As Integer) As String()
'ADO.Net
Dim strCn As String = System.Configuration.ConfigurationManager.ConnectionStrings("JC").ConnectionString
cn.ConnectionString = strCn
Dim cmd As New SqlClient.SqlCommand
cmd.Connection = cn
cmd.CommandType = CommandType.Text
'Compare String From Textbox(prefixText)
'AND String From Column in DataBase(CompanyName)
'If String from DataBase is equal to String from TextBox(prefixText)
'then add it to return ItemList
'-----I defined a parameter instead of passing value
'directly to prevent SQL injection--------'
cmd.CommandText = "select * from product Where Name like @myParameter"
cmd.Parameters.AddWithValue("@myParameter", "%" + prefixText + "%")
Try
cn.Open()
cmd.ExecuteNonQuery()
Dim da As New SqlDataAdapter(cmd)
da.Fill(ds)
Catch ex As Exception
Finally
cn.Close()
End Try
dt = ds.Tables(0)
'Then return List of string(txtItems) as result
Dim txtItems As New List(Of String)
Dim dbValues As String
For Each row As DataRow In dt.Rows
''String From DataBase(dbValues)
dbValues = row("Name").ToString()
dbValues = dbValues.ToLower()
txtItems.Add(dbValues)
Next
Return txtItems.ToArray()
End Function
End Class
'''''''''''''''''''''''''''''<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="testingdel.aspx.vb" Inherits="Bestpaisa.testingdel" %><%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"><link href="Autocomplete.css" rel="stylesheet" type="text/css" /><title></title></head><body><form id="form1" runat="server"><div><asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager><asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl="~/Products/kids">sdfsdfsdf
HyperLink</asp:HyperLink><asp:TextBox ID="myTextBox" runat="server" autocomplete ="off"></asp:TextBox><asp:AutoCompleteExtender ID="autoComplete1" runat="server"
EnableCaching="true"
BehaviorID="AutoCompleteEx"
MinimumPrefixLength="2"
TargetControlID="myTextBox"
ServicePath="AutoComplete.asmx"
ServiceMethod="GetCompletionList"
CompletionInterval="1000"
CompletionSetCount="20"
CompletionListCssClass="autocomplete_completionListElement"
CompletionListItemCssClass="autocomplete_listItem"
CompletionListHighlightedItemCssClass="autocomplete_highlightedListItem"
DelimiterCharacters=";, :"
ShowOnlyCurrentWordInCompletionListItem="true"><Animations><OnShow><Sequence><%-- Make the completion list transparent and then show it --%><OpacityAction Opacity="0" /><HideAction Visible="true" /><%--Cache the original size of the completion list the first time
the animation is played and then set it to zero --%><ScriptAction Script="// Cache the size and setup the initial size
var behavior = $find('AutoCompleteEx');
if (!behavior._height) {
var target = behavior.get_completionList();
behavior._height = target.offsetHeight - 2;
target.style.height = '0px';
}" /><%-- Expand from 0px to the appropriate size while fading in --%><Parallel Duration=".4"><FadeIn /><Length PropertyKey="height" StartValue="0"
EndValueScript="$find('AutoCompleteEx')._height" /></Parallel></Sequence></OnShow><OnHide><%-- Collapse down to 0px and fade out --%><Parallel Duration=".4"><FadeOut /><Length PropertyKey="height" StartValueScript="$find('AutoCompleteEx')._height" EndValue="0" /></Parallel></OnHide></Animations></asp:AutoCompleteExtender></div></form></body></html>↧
problem with the code
↧