0

I didn't write the function for the AutoCompleteExtender so I am not quite sure how to change it without screwing it up, so I figured I would ask here. Recently, it was requested that the AutoComplete show a product name & the date of launch of that specific product. I do not know how to add the date to the AutoComplete.

The reason this is needed is because the webinars we give out are shown again in the future, so there are multiple webinars with the same name in the database. It is a little difficult to choose one webinar when searching when there are 3 with the exact same name, so if it shows the name and the date, I would imagine it would be easier to choose the right one!

The way this is written right now is incorrect. I get a squiggly line underneath the word launchdate in the line Dim item As String = AjaxControlToolkit...... and the error is: Too many arguments to 'Public Shared Function CreateAutoCompleteItem(text As String, value As String) As String'

Any help is greatly appreciated! Like I said, I didn't write this, so I don't even know if this is best practice. I understand if you want to criticize the code, and I will change it if it needs it, but I would really like to know how to add the extra field too. Thanks!

Public Function GetProducts(ByVal prefixText As String, ByVal count As Integer) As String()
    Dim ProductSql As String = "Select DISTINCT ProductID, ProductName, LaunchDate 
                                FROM Product 
                                WHERE ProductName LIKE '%' + @prefixText + '%' 
                                AND LaunchDate IS NOT NULL 
                                ORDER BY ProductName ASC"
    Using sqlConn As New SqlConnection
(System.Configuration.ConfigurationManager.ConnectionStrings("LocalSqlServer").ConnectionString)
        sqlConn.Open()
        Dim myCommand As New SqlCommand(ProductSql, sqlConn)
        myCommand.Parameters.Add("@prefixText", SqlDbType.VarChar, 50).Value = prefixText
        Dim myReader As SqlDataReader = myCommand.ExecuteReader()
        Dim myTable As New DataTable
        myTable.TableName = "ProductSearch"
        myTable.Load(myReader)
        sqlConn.Close()
        Dim items As String() = New String(myTable.Rows.Count - 1) {}
        Dim i As Integer = 0
        For Each dr As DataRow In myTable.Rows
            Dim id As String = dr("ProductID").ToString()
            Dim name As String = dr("ProductName").ToString()
            Dim launchdate As String = dr("LaunchDate").ToString()
            Dim item As String = 
            AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(name, id, launchdate)
            items.SetValue(item, i)
            i += 1
        Next
        Return items
    End Using
End Function
Jamie
  • 1,579
  • 8
  • 34
  • 74

1 Answers1

0

Try this..

AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(name & " " & launchdate, id) 
NoAlias
  • 9,218
  • 2
  • 27
  • 46
  • Perfect! Thanks. You don't happen to know how I can change the display of the launchdate from a datetime to show the date in the autocomplete do you? (mm-dd-yyyy) – Jamie Mar 01 '12 at 17:33
  • .ToString("MM-dd-yyyy") 'Case sensitive. – NoAlias Mar 01 '12 at 18:40
  • Hmmm...that breaks the autocompleteextender. Nothing shows up in the dropdown now. – Jamie Mar 01 '12 at 19:54
  • Do it when you're setting the value of the launchdate variable from the data row. – NoAlias Mar 01 '12 at 21:24
  • that is where I did it. In the `Dim launchdate As String` line. I'm trying different combinations to see if anything will work but so far nothing is working right. – Jamie Mar 01 '12 at 21:43