首次单击时,将使用所有可能性自动填充AutoCompleteExtender [英] Auto populate AutoCompleteExtender with all possibilities on first click

查看:106
本文介绍了首次单击时,将使用所有可能性自动填充AutoCompleteExtender的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试让autoCompleteExtender填充所有可能的文本框焦点.到目前为止,我还没有运气.我尝试在textbox标记中添加onfucus来调用js函数,该函数调用web方法从数据表填充数据而没有运气.正在调用Web方法,但页面上没有任何显示.只有在文本框中输入内容后,才会出现任何建议. 这是aspx页面控件:

I am trying to have autoCompleteExtender to populate on focus of a textbox all possibilities. So far I am having no luck. I have tried adding onfucus in the textbox tag to call a js function that calls the webmethod to populate from a datatable with no luck. The webmethod is being called but nothing shows up on the page. Only after typing something in the textbox does any suggestions turn up. Here is the aspx page control:

<div title="Model" runat="server" style="text-align:left; padding:20px"><strong>Model</strong>
                <asp:TextBox ID="tbModel" runat="server" onfocus="ModelTBOnFocus()"></asp:TextBox>
                <div id="ModelListPlacement" style="height:100px; overflow-y:scroll;" ></div>
                    <ajaxToolkit:AutoCompleteExtender ID="tbModel_AutoCompleteExtender" runat="server" DelimiterCharacters=""
                        Enabled="True" ServiceMethod="GetListofModels" MinimumPrefixLength="1" EnableCaching="true"
                        ServicePath="" TargetControlID="tbModel" CompletionInterval="50" CompletionSetCount="40"
                        CompletionListElementID="ModelListPlacement"></ajaxToolkit:AutoCompleteExtender>
            </div>

这是webMethod的CodeBehind:

And Here is the CodeBehind webMethod:

[System.Web.Script.Services.ScriptMethod()]
        [System.Web.Services.WebMethod]
        public static List<string> GetListofModels(string prefixText)
        {
            using (SqlConnection sqlconn = new SqlConnection(GetConnectionStringValue("")))
            {
                sqlconn.Open();
                SqlCommand cmd = new SqlCommand("SELECT DISTINCT(Model) FROM Assets WHERE Model like '" + prefixText + "%' " + ModelQuery, sqlconn);
                cmd.Parameters.AddWithValue("@Model", prefixText);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                List<string> Models = new List<string>();
                TextInfo myTI = CultureInfo.CurrentCulture.TextInfo;
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    string model = myTI.ToTitleCase(dt.Rows[i]["Model"].ToString().ToLower());
                    Models.Add(model);
                }
                return Models;
            }
        }

这是工作代码.我只是想让所有的可能性在文本框被聚焦时显示出来.任何帮助将非常感激.谢谢!

This is working code. I am just trying to get all possibilities to show up when the textbox is focused. Any help would be much appreciated. Thanks!

该js也可以正常工作,但是直到输入内容后我才得到任何建议. 这是调用该函数的javascript代码:

This js is working also, but I am not getting any suggestions until something is typed. Here is the javascript code to call the function:

<script type="text/javascript">
        function ModelTBOnFocus() {
            PageMethods.GetListofModels("");
        }
</script>

推荐答案

找到了我的答案: 为了解决此问题,我必须设置MinimumPrefixLength ="0"

Found my answer: In order to solve this problem I had to set the MinimumPrefixLength="0"

这篇关于首次单击时,将使用所有可能性自动填充AutoCompleteExtender的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆