title: ASP.NET: How to create a search function just using a textbox?
body: <p>I would like to have suggestions with regards to having a search function in my website. It will be to find the registered customers so that it will be easier for the admin to look for a specific customer.</p>
  
  <p>Can you give sample code snippets so that I can accomplish this specific search function? </p>
  
  <p>Thank you.</p>
  
  <p>Here is my .aspx code</p>
  
  <pre><code>  &lt;asp:TextBox ID="txtSearch" runat="server" BorderStyle="Solid" Width="218px" 
          ontextchanged="txtSearch_TextChanged"&gt;&lt;/asp:TextBox&gt;
  &amp;nbsp;&lt;asp:Button ID="btnSearch" runat="server" Text="Search" /&gt;
  &lt;/p&gt;
  &lt;div style="overflow-x:auto; width:1200px"&gt;
   &lt;asp:GridView ID="gvCustomer" runat="server" AutoGenerateColumns="False" 
          BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px" 
          Caption="Customer Profile" CellPadding="4" CellSpacing="2" DataSourceID="SqlDataSourceBM" 
          ForeColor="Black" onrowcommand="gvCustomer_RowCommand" 
          DataKeyNames="ApplicantUsername" &gt;
          &lt;Columns&gt;
              &lt;asp:BoundField DataField="Branch" HeaderText="Branch" 
                  SortExpression="Branch" /&gt;
              &lt;asp:BoundField DataField="ApplicantUsername" HeaderText="Username" 
                  SortExpression="ApplicantUsername" ReadOnly="True" /&gt;
              &lt;asp:BoundField DataField="NoAFirstName" HeaderText="First Name" 
                  SortExpression="NoAFirstName" /&gt;
              &lt;asp:BoundField DataField="NoALastName" HeaderText="Last Name" 
                  SortExpression="NoALastName" /&gt;
              &lt;asp:ButtonField CommandName="View Profile" HeaderText="Customer Profile" 
                  Text="View" /&gt;
              &lt;asp:ButtonField CommandName="Edit" HeaderText="Customer Profile" Text="Edit" /&gt;
              &lt;asp:ButtonField CommandName="View CR" HeaderText="Credit Report" Text="View" /&gt;
          &lt;/Columns&gt;
          &lt;FooterStyle BackColor="#CCCCCC" /&gt;
          &lt;HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" /&gt;
          &lt;PagerStyle BackColor="#CCCCCC" ForeColor="Black" HorizontalAlign="Left" /&gt;
          &lt;RowStyle BackColor="White" /&gt;
          &lt;SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" /&gt;
          &lt;SortedAscendingCellStyle BackColor="#F1F1F1" /&gt;
          &lt;SortedAscendingHeaderStyle BackColor="#808080" /&gt;
          &lt;SortedDescendingCellStyle BackColor="#CAC9C9" /&gt;
          &lt;SortedDescendingHeaderStyle BackColor="#383838" /&gt;
      &lt;/asp:GridView&gt;
      &lt;asp:SqlDataSource ID="SqlDataSourceBM" runat="server" 
          ConnectionString="&lt;%$ ConnectionStrings:PFCIConnectionString %&gt;" 
  
  
          SelectCommand="SELECT [ApplicantUsername], [Branch], [NoALastName], [NoAFirstName] FROM [CustomerRegistration] WHERE (([Branch] = @Branch) AND ([NoALastName] LIKE '%' + @NoALastName + '%'))"&gt;
          &lt;SelectParameters&gt;
              &lt;asp:SessionParameter Name="Branch" SessionField="ApplicantUsername" 
                  Type="String" /&gt;
              &lt;asp:ControlParameter ControlID="txtSearch" Name="NoALastName" 
                  PropertyName="Text" Type="String" /&gt;
          &lt;/SelectParameters&gt;
      &lt;/asp:SqlDataSource&gt;
  </code></pre>