Jquery/ajax:从文本框中的子字符串自动完成ajax ?

时间:2021-11-12 03:18:01

I have this txt_Remarks textbox in asp.net, what I have done is used ajaxToolkitLibrary to specify a source of autocompletion list which is defined like this,

我在asp.net中有这个txt_comments文本框,我所做的是使用ajaxToolkitLibrary指定自动完成列表的一个源,

[WebMethod]
public string[] GetItemRemarks(string prefixText, int count)
{
    if (count == 0)
    {
        count = 10;
    }

    Random random = new Random();
    List<string> items = new List<string>(count);
    SqlCommand con = new SqlCommand();
    SqlDataReader sdr = null;
    try
    {
        SqlCommand cmd = new SqlCommand();
        cmd.CommandText = "SELECT REMARKS FROM mstRemark WHERE BranchId='"+ Globals.BranchID +"' AND Id<>1 AND REMARKS like '%" + prefixText.Trim() + "%' ";
        sdr = ExecuteReader(cmd);
        while (sdr.Read())
        {
            items.Add("" + sdr.GetValue(0));
        }
        sdr.Close();
        sdr.Dispose();
    }
    catch (Exception )
    {

    }
    return items.ToArray();
}

what I want it, after a item is select say premium user instead of ending auto complete, a comma be put there and new list of item is shown to user based on what he is typing right now.

我想要的是,在一个项目被选择为高级用户而不是结束自动完成后,在那里放一个逗号然后根据用户现在输入的内容显示新的项目列表。

say, he starts typing p== its shows premium, predefined, pattern, etc.. when he clicks premium, it gets set in text box, and then a comma be put there, and he can type again, say he again types p== it should show again premium, predefined, pattern, this time he clicks pattern, the textbox would show preminum, pattern and allows him to work like this until he clicks somewhere else. So, basically this autocomplete should work based a custom substring, I also tried using $.ajax() but no luck, I couldn't even get it to work for that matter.. So, how can this be done?

例如,他开始键入p==它的显示值、预定义的、模式等。当他点击高级,设置文本框,然后一个逗号放在那里,他又能打,说他又类型p = =应该溢价再次显示,预定义的模式,这一次他点击模式,文本框会显示preminum,模式和允许他这样的工作,直到他点击其他地方。因此,基本上这个autocomplete应该可以基于一个自定义子字符串工作,我也尝试过使用$.ajax(),但不幸的是,我甚至无法让它工作。那么,如何做到这一点呢?

EDIT: something like what happends in * when you enter a start typing a tag, it shows a list, when u select it, it is entered into box, and you can type again and that tag is added to the list..

编辑:类似*里面的东西当你输入一个开始输入一个标签时,它会显示一个列表,当你选择它时,它会被输入到框中,你可以再次输入,那个标签会被添加到列表中。

1 个解决方案

#1


1  

You could checkout the Chosen jquery plugin, it does pretty much exactly what you're describing I believe.

你可以签出所选的jquery插件,它所做的和你所描述的差不多。

http://harvesthq.github.com/chosen/

http://harvesthq.github.com/chosen/

#1


1  

You could checkout the Chosen jquery plugin, it does pretty much exactly what you're describing I believe.

你可以签出所选的jquery插件,它所做的和你所描述的差不多。

http://harvesthq.github.com/chosen/

http://harvesthq.github.com/chosen/