将数据库值获取到搜索文本框 [英] get database values to a search textbox

查看:102
本文介绍了将数据库值获取到搜索文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hey guyz,



有人能告诉我如何将数据库数据传输到搜索文本框吗?即时通讯使用html,jsp,servlet,java与DAO概念。在这里,当我输入一个字母(例如:ma)时,它应该显示以ma开头的列表。然后用户选择其中一个。用户将在下面的选择中看到相关细节。还有其他可能的方法吗?

这里我的HTML代码

hey guyz,

Can anyone tell me how to get database data to a search textbox? im using html, jsp, servlet, java with DAO concepts. in here when I enter a letter (ex: ma) then it should show the list which are starting with "ma". Then user selects one of them. After user will see relavent details in that selection bellow. Is there any other possible ways?
here my html code

<div id="page">
            <form name="input" action="book" method="post">
                Book      :       <input type="text" name="txtBid" class="resizedTextbox"><br><br>
                               
                <input type="submit" value="Search Book" onclick= <a href="main/Servelet"</a>      
                <input type="hidden" name="operation" value="searchBook"><br><br>                
                               
                <input type="submit" value="Reserve" onclick= <a href="main/Servelet"</a>
                <input type="hidden" name="operation" value="deleteBook">	
                <input type="reset" value="Cancel/Clear" onclick= <a href="main/Servelet"</a>
                <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
            </form>
        </div>





感谢提前..!



Thankx in advance..!

推荐答案

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


这篇关于将数据库值获取到搜索文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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