Wednesday, March 21, 2012

A premium AutoComplete for AJAX?

Is there anyway to emulate the complete functionality of the comboBox control in MS Access that includes Autocomplete, column headers etc? I've seen some 3rd party ones, but am not at liberty at my company to acquire them.

I've used the autocomplete extender but I really need the column headers and "not-in-list" event. I was thinking I could use a datagrid or datalist to emulate this.

hi,

check this

http://ajax.asp.net/ajaxtoolkit/AutoComplete/AutoComplete.aspx


I'm sorry. I guess I should have mentioned thathttp://ajax.asp.net/ajaxtoolkit/AutoComplete/AutoComplete.aspx was mystarting point.
Presently, I am showing Cost Center numbers in one column. What I would like to do is have an additional column that displays a name description. If I were to add yet a third column, which is a possibility, it would just be nice to be able to display the column headers just as you do in Microsoft Access.


Here's what I have so far in the autocomplete.asmx (ONE column) , please help me adjust this for additional columns.

<%@.WebServiceLanguage="VB"Class="autocomplete" %>

Imports System.Web
Imports System.Web.Services
Imports System.Web.Services.Protocols
Imports System.Data
Imports System.Data.SqlClient
Imports System.Collections.Generic

<WebService(Namespace:="http://tempuri.org/")> _
<WebServiceBinding(ConformsTo:=WsiProfiles.BasicProfile1_1)> _
<System.Web.Script.Services.ScriptService()> _

PublicClass autocomplete
Inherits System.Web.Services.WebService

<WebMethod()> _

PublicFunction GetSuggestionsFromDataset(ByVal prefixTextAsString,ByVal countAsInteger)AsString()

' Define data set

Dim dsAsNew DataSet()
Dim dtAsNew DataTable()
Dim drAs SqlDataReader = PurchasingBLL.GetCostCenters
Dim daAsNew PurchasingTableAdapters.tbl_CostCenterTableAdapter ds.Tables.Add(dt)
dt.Columns.Add(New DataColumn("Word",GetType(String)))
dt.Rows.Add("Cost Center")

DoWhile dr.Read
dt.Rows.Add(New ListItem(dr("FullCCNum")))
Loop

Dim suggestionsAsNew List(OfString)()
Dim wordsAs DataRow() = dt.[Select]("Word LIKE '" + prefixText +"%'")
Dim numAsInteger = IIf((words.Length < count), words.Length, count)

For iAsInteger = 0To num - 1
suggestions.Add(DirectCast(words(i)("Word"),String))
Next

Return suggestions.ToArray()

EndFunction

EndClass

I suppose I could put a "label" or something underneath the textbox, but I notice that the extender attaches exactly "Flushed" at the bottom, so I probably have to do some trickery to make that happen. Any suggestions?


This is not currently supported. We do want to allow users to set custom datatypes in the autocomplete flyouts bound to item templates but we are still investigating that approach.


Ok, then what about something less daunting like perhaps just helping me add another column in the web service?
I'm confused of the exact useage of the array ("suggestions") that was provided in the example.

I tried this, but it still only returns one column, - and as you can see, I haven't touched the "Suggestions" array.
Or -- is adding column headers specifically what is not supported?

dt.Columns.Add(New DataColumn("Word",GetType(String)))
dt.Columns.Add(New DataColumn("Descr",GetType(String)))

dt.Rows.Add("Cost Center")
DoWhile dr.Read
dt.Rows.Add(New ListItem(dr("FullCCNum")))
Loop

dt.Rows.Add("Description")

DoWhile dr.Read
dt.Rows.Add(New ListItem(dr("CC_Descr")))
Loop


Hi, may be you can consider returning a string array can represent the result in a well formated way?

For instance:

[System.Web.Services.WebMethod]
[System.Web.Script.Services.ScriptMethod]
public static string[] GetCompletionList(string prefixText, int count)
{
string[] words = prefixText.Split(new char[] { ';' });
string[] result = new string[16];
for (int i = 0; i < 16; i++)
{
result[i] = datarow["column1"] + "\t[ Use a tab to separate different columns ]" + datarow["column2"] ;
}
return result;
}


Would you mind translating to Visual Basic-- I have a translator, but it doesn't like that usage of datarow:

PublicSharedFunction GetCompletionList(ByVal prefixTextAsString,ByVal countAsInteger)AsString()
Dim wordsAsString() = prefixText.Split(NewChar() {";"c})
Dim resultAsString() =NewString(15) {}

For iAsInteger = 0To 15
result(i) = DataRow("column1") +"" & Chr(9) &"[ Use a tab to separate different columns ]" + DataRow("column2")
Next

Return result

EndFunction

No comments:

Post a Comment