且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将数据库值获取到搜索文本框

更新时间:2022-04-21 22:45:46

http://jqueryui.com/autocomplete/ [ ^ ]



自动填充-文本框-with-database-in-jsp-and-follow-the-MVC-model.html [ ^ ]



创建自动填充文本框 [ ^ ]
http://jqueryui.com/autocomplete/[^]

Autocomplete-textbox-with-database-in-jsp-and-follow-the-MVC-model.html[^]

Creating autocomplete textbox[^]


从ajax工具包中应用自动完成扩展程序spx页面如下





apply auto complete extender from ajax tool kit in your aspx page as below


<asp:TextBox ID="Item_Name" runat="server" Width="200px"

            ontextchanged="Item_Name_TextChanged" AutoPostBack="True" TabIndex="2"></asp:TextBox>
        <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" CompletionInterval="500" MinimumPrefixLength="1" ServiceMethod="Getdata"

                        TargetControlID="Item_Name" UseContextKey="True">
        </asp:AutoCompleteExtender>











和.cs文件生成如下函数








and in .cs file make a function as below

[System.Web.Services.WebMethodAttribute(), System.Web.Script.Services.ScriptMethodAttribute()]
       public static string[] Getdata(string prefixText, int count, string contextKey)
       {
           SqlConnection con1 = new SqlConnection(Connection.getConnectionString());
           con1.Open();

           DataTable dt = new DataTable();
           SqlCommand cmd = new SqlCommand();
           SqlDataAdapter adap = new SqlDataAdapter("Your sql Query", con1);
           adap.Fill(dt);

           string[] main = new string[0];
           int j = dt.Rows.Count;
           for (int i = 0; i < j; i++)
           {
               //if (ds.Tables[0].Rows[i].ItemArray[0].ToString().ToLower().StartsWith(prefixText.ToLower()))
               if (dt.Rows[i].ItemArray[0].ToString().ToLower().Contains(prefixText.ToLower()))
               {
                   Array.Resize(ref main, main.Length + 1);
                   //main[main.Length - 1] = ds.Tables[0].Rows[i].ItemArray[0].ToString();
                   main[main.Length - 1] = dt.Rows[i].ItemArray[0].ToString();
                   if (main.Length == 15)
                       break;
               }
           } con1.Close();
           Array.Sort(main);
           return main;
       }


看看下面的链接:



http://www.java4s.com/jquery -tutorials / example-get-autocomplete-feature-in-javajsp-with-jquery-api / [ ^ ]



http://viralpatel.net/blogs/tutorial-create-autocomplete-feature-with -java-JSP-的jquery / [ ^ ]



-anurag
Have a look at below links:

http://www.java4s.com/jquery-tutorials/example-get-autocomplete-feature-in-javajsp-with-jquery-api/[^]

http://viralpatel.net/blogs/tutorial-create-autocomplete-feature-with-java-jsp-jquery/[^]

-anurag