|
Autosuggest text box example, only need one text box to auto-suggest -- bubberz --
Hello! I'm following the example, and only need one text box to auto-suggest. http://munich.schwarz-interactive.de/autocomplete.aspx My table, Signature_Authority_Names, has a field I'd like to pull in which is both the last name and first name togeter, Authority. I'm assuming the code behind for SearchAdvanced function is for the second autosuggest text box...right?...which I don't need. I'm trying to follow the example, but getting no data to populate. Here's my code, and I do have AjaxPro.dll as a reference ******** ******** web.config </system.web> <location path="ajaxpro"> <system.web> <httpHandlers> <add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/> </httpHandlers> </system.web> </location> </configuration> ********** ********** my .aspx code behind (WebForm2.aspx.vb) Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load AjaxPro.Utility.RegisterTypeForAjax(GetType(WebForm2)) End Sub <AjaxPro.AjaxMethod()> _ Public Function SearchAdvanced(ByVal orderNumber As String, ByVal customerID As Integer, ByVal count As Integer) As DataTable Dim ds As DataSet = New DataSet 'Dim conn As SqlConnection = New SqlConnection(ConfigurationSettings.AppSettings("AjaxDemoSqlServer")) Dim cmd As New OleDbCommand("SELECT Authority FROM Orders Signature_Authority_Names WHERE Authority like @CustomerID" + "%") '+ '"AND OrderNumber LIKE @OrderNumber " + ' "ORDER BY OrderNumber, PartNumber, JobNumber", conn) cmd.Parameters.Add("@CustomerID", customerID) 'cmd.Parameters.Add("@OrderNumber", orderNumber + "%") Try conn.Open() Dim da As OleDbDataAdapter = New OleDbDataAdapter(cmd) da.Fill(ds) conn.Close() Catch Return Nothing Finally conn.Close() End Try 'Return ds.Tables.Count =1 ? ds.Tables(0) : Nothing 'ds.Tables.Count = 1 ? ds.Tables(0) : Nothing End Function <AjaxPro.AjaxMethod()> _ Public Function Search(ByVal strsearch As String, ByVal count As Integer) As DataTable Dim dt As DataTable = New DataTable dt.Columns.Add("CustomerID", GetType(Integer)) dt.Columns.Add("CustomerName", GetType(String)) Try conn.Open() Dim cmd As OleDbCommand = New OleDbCommand("SELECT TOP " + count + " ID, Name FROM Signature_Authority_Names WHERE Authority LIKE @Name ORDER BY Name", conn) cmd.Parameters.Add("@Name", strsearch + "%") Dim dr As OleDbDataReader = cmd.ExecuteReader() Dim row As DataRow While dr.Read() If dr(0) Is System.DBNull.Value Or dr(1) Is System.DBNull.Value Then row = dt.NewRow() row("CustomerID") = dr(0) row("CustomerName") = dr(1) dt.Rows.Add(row) End If End While Catch ex As Exception Throw ex End Try Return dt End Function ****************** ****************** My html is only one text box for now to get the example down, and the page's name is WebForm2.aspx and the application name is AjaxTesting1. <HTML> <HEAD> <title>WebForm2</title> <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content=" http://schemas.microsoft.com/intellisense/ie5 "></HEAD> <body MS_POSITIONING="GridLayout"> <script type="text/javascript" src="scripts/autocomplete.js"></script> <script type="text/javascript"> function init() { var x = new MS.Web.AutoCompleteDataTable("searchCustomerID", 10); x.getDisplay = function(item) { return (item != null ? item.CustomerName : ""); } x.getValue = function(item) { return (item != null ? item.CustomerName.toString().trimRight() : ""); } x.getData = function() { AjaxTesting1.WebForm2.AjaxMethod(this.ele.value, this.count, this.callback.bind(this)); } } addEvent(window, "load", init); </script> <form id="Form1" method="post" runat="server"> <asp:TextBox id="searchCustomerID" style="Z-INDEX: 101; LEFT: 104px; POSITION: absolute; TOP: 64px" runat="server" Width="352px"></asp:TextBox> </form> </body> </HTML> Thanks for the help. I know this will help tremendously! |