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
Try this..
AjaxControlToolkit.AutoCompleteExtender.CreateAutoCompleteItem(name & " " & launchdate, id)