开发者

Autocomplete accepting one sql value, not multiple

Im currently diving into jquery autocomplete for the first time. To start off with, I had a .net handler calling out to a mssql db and pulling last names. That worked great.

However when I try to add additional values it simply doesnt work. The code being used in the handler is as follows.

    Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
    Dim prefixText As String = context.Request.QueryString("term")

    Dim conn As SqlConnection = New SqlConnection
    conn.ConnectionString = ConfigurationManager.AppSettings("CDBPath")

    Dim cmd As SqlCommand = New SqlCommand
    cmd.CommandText = ("Select Ebase.EbLastname, Ebase.EbFirstname, Ejob.EjTitle, Ebase.EbClock " + _
                        "From Ebase " + _
                        "INNER Join Ejob " + _
                        "ON Ebase.EbFlxID = Ejob.EjFlxIDEb " + _
                        "Where Ebase.EbLastname LIKE @SearchText + '%'" + _
                        "And Ebase.EbDateEnd Is Null " + _
                        "And Ejob.EjDateEnd Is Null")

    cmd.Parameters.AddWithValue("@SearchText", prefixText)
    cmd.Connection = conn

    Dim sb As StringBuilder = New StringBuilder
    conn.Open()
    Dim sdr As SqlDataReader = cmd.ExecuteReader

    While sdr.Read
        sb.Append(sdr("EbLastname")).Append(", ").Append(sdr("EbFirstname")).Append(" - ").Append(sdr("EjTitle")).Append(", ").Append(sdr("EbClock")).Append(Environment.NewLin开发者_开发问答e)
    End While
    conn.Close()
    context.Response.ContentType = "application/json"
    context.Response.Write(sb.ToString)

End Sub

I didnt include the IsReusable when posting, but that is there. Is there something really simple that I'm missing in why it doesnt like multiple values but will display one lone value?

** Edit ** To clarify, I just looked in Firebug and it is getting a response but just not displaying it. My implementation of this is pretty simple so far, nothing to fancy.

        $(function() {
        $('#lastName').autocomplete
        ({
            source: "FormAutoComplete.ashx",
            minChars: 3

        });
    })


If you're returning multiple values you have to monkey with the parsing and formatting of the item. Here's an example of what I've done in the past. It returns a json object like this:

{ City: "Charleston", State: "SC", Code: "chs" }

and formats it into Charleston, SC and uses the Code for the actual value that gets displayed in the textbox.

$areas.autocomplete(data, {
            formatItem: function (item) {
                return item.City + ", " + item.State;
            },
            formatResult: function (item) {
                return item.Code;
            },
            multiple: true
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜