Click here to Skip to main content
15,886,639 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
HTML
<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..!
Posted

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


XML
<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>





and in .cs file make a function as below

C#
[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;
       }
 
Share this answer
 
v2
Comments
mali_angel 12-Sep-13 22:48pm    
i m using java..can u tell me this in java?
XML
<html lang="en">
<head>
  <meta charset="utf-8" />
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css" />
  <script src="http://code.jquery.com/jquery-1.9.1.js"></script>
  <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
  <link rel="stylesheet" href="/resources/demos/style.css" />
  <script>
  $(function() {
    var availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",
      "C",
      "C++",
      "Clojure",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Groovy",
      "Haskell",
      "Java",
      "JavaScript",
      "Lisp",
      "Perl",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ];
    $( "#tags" ).autocomplete({
      source: availableTags
    });
  });
  </script>
</head>
<body>

<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags" />
</div>


</body>
</html>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900