title: Search with autocomplete and Ajax
body: <p>I want to make a search like them from google. </p>
  
  <p>I've made it this far, that I can show all data from the database in my textbox with using a webservice. Thats my code:</p>
  
  <p><strong>Webform.aspx</strong></p>
  
  <pre><code>&lt;%--**Start Search**--%&gt;
  &lt;asp:ScriptManager ID="ScriptManager1" runat="server"&gt;
      &lt;Services&gt;&lt;asp:ServiceReference Path="~/WebService.asmx" /&gt;&lt;/Services&gt;
  &lt;/asp:ScriptManager&gt;
  &lt;%--Search-Textbox--%&gt;
  &lt;asp:TextBox runat="server" ID="txtSearchInput" Width="100%" /&gt;
  &lt;asp:Button ID="btnSearch" runat="server" Text="Suche" onclick="btnSearch_Click" /&gt;
  &lt;%--Autocomplete (Ajax)--%&gt;
  &lt;asp:AutoCompleteExtender ID="AutoComplete1" runat="server" TargetControlID="txtSearchInput"
     ServiceMethod="GetNames" ServicePath="~/WebService.asmx" MinimumPrefixLength="1"  
     EnableCaching="true" CompletionInterval="1000" CompletionSetCount="20"&gt;
  &lt;/asp:AutoCompleteExtender&gt;
  &lt;%--**End Search**--%&gt;
  </code></pre>
  
  <p><strong>Webservice.asmx</strong></p>
  
  <pre><code>[WebMethod]
  public string[] GetNames(string prefixText, int count)
  {
      List&lt;string&gt; items = new List&lt;string&gt;(count);
      DataSet ds = new DataSet();
  
      string cs = ConfigurationManager.ConnectionStrings["CSLinker"].ConnectionString;
  
      using (SqlConnection connection = new SqlConnection(cs))
      {
          string sql = "SELECT Name FROM tabProjects WHERE Name LIKE '" + prefixText + "%' UNION all SELECT Name FROM tabLinks WHERE Name LIKE '" + prefixText + "%'";
          SqlDataAdapter adapter = new SqlDataAdapter();
          adapter.SelectCommand = new SqlCommand(sql, connection);
          adapter.Fill(ds);
      }
  
      foreach (DataRow dr in ds.Tables[0].Rows)
      {
          items.Add(dr["Name"].ToString());
      }
      return items.ToArray();
  }
  </code></pre>
  
  <p>My problem now is, that i only have the name from the database. But for the search I need also the ID. Can somebody say me, how I can also query the ID without showing it in the textform? 
  I hope you can understand my problem. My english isnt' so good...</p>
  
  <p>Thanks for helping!</p>