title: How to Search a GridView?
body: <p>I have a textbox and search button. Currently the Search button doesn't do anything. I do not know how to search in a GridView. I have researched for a few hours and the examples do not work because I use Stored Procedures (one is a select statement that works for this GridView, meanwhile I see I would need some other select to get the search... but I don't see how to incorporate two selects here). How can I add a search to this?</p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/admin/admin.master" AutoEventWireup="true" CodeFile="viewregistrantpaper.aspx.cs" Inherits="viewreg" %&gt;
  
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"&gt;
  &lt;/asp:Content&gt;
  &lt;asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"&gt;
  &lt;h1&gt;View Registrant&lt;/h1&gt;
  
      &lt;asp:TextBox ID="TxtSearch" runat="server" CssClass="formtextbox"&gt;&lt;/asp:TextBox&gt;
          &lt;asp:Button ID="BtnSearch" runat="server" onclick="BtnSearch_Click" Text="Search" CssClass="formbutton" /&gt;
  
  
          &lt;asp:GridView ID="GridView1"  runat="server" AllowPaging="True" 
              AllowSorting="True" AutoGenerateColumns="False" 
              DataSourceID="SqlDataSourceViewRegistrant"  
              CssClass="mGrid"  
      PagerStyle-CssClass="pgr"  
      AlternatingRowStyle-CssClass="alt" &gt;
  &lt;AlternatingRowStyle CssClass="alt"&gt;&lt;/AlternatingRowStyle&gt;
  
              &lt;Columns&gt;
  
  
                  &lt;asp:CommandField ShowDeleteButton="True" ShowEditButton="True" /&gt;
  
  
                  &lt;asp:BoundField DataField="LocalNumberId" HeaderText="Local" 
                      SortExpression="LocalNumberId" /&gt;
                  &lt;asp:BoundField DataField="LocalUnionEmail" HeaderText="Local Email" 
                      SortExpression="LocalUnionEmail" /&gt;
                  &lt;asp:BoundField DataField="DistrictId" HeaderText="District" 
                      SortExpression="DistrictId" /&gt;
                  &lt;asp:BoundField DataField="CompletedByFirstName" HeaderText="Completed By First Name" 
                      SortExpression="CompletedByFirstName" /&gt;
                  &lt;asp:BoundField DataField="CompletedByLastName" HeaderText="Completed By Last Name" 
                      SortExpression="CompletedByLastName" /&gt;
                  &lt;asp:BoundField DataField="CompletedByPhone" HeaderText="Completed By Phone" 
                      SortExpression="CompletedByPhone" /&gt;
                  &lt;asp:BoundField DataField="FirstName" HeaderText="First Name" 
                      SortExpression="FirstName" /&gt;
                  &lt;asp:BoundField DataField="LastName" HeaderText="Last Name" 
                      SortExpression="LastName" /&gt;
                  &lt;asp:BoundField DataField="Position" HeaderText="Position" 
                      SortExpression="Position" /&gt;
                  &lt;asp:BoundField DataField="Email" HeaderText="Email" 
                      SortExpression="Email" /&gt;
                  &lt;asp:BoundField DataField="ShirtSize" HeaderText="Shirt Size" 
                      SortExpression="ShirtSize" /&gt;
                  &lt;asp:BoundField DataField="Comments" HeaderText="Comments" 
                      SortExpression="Comments" /&gt;
              &lt;/Columns&gt;
  
  &lt;PagerStyle CssClass="pgr"&gt;&lt;/PagerStyle&gt;
  
          &lt;/asp:GridView&gt;
      &lt;div style=" width:100%; overflow: hidden;"&gt;
          &lt;asp:SqlDataSource ID="SqlDataSourceViewRegistrant" runat="server" 
              ConnectionString="&lt;%$ ConnectionStrings:Events2 %&gt;" 
              DeleteCommand="spDelRegistrant" DeleteCommandType="StoredProcedure" 
              InsertCommand="spInsRegistrantPaper" InsertCommandType="StoredProcedure" 
              SelectCommand="spGetRegistrantPaper" SelectCommandType="StoredProcedure" 
              UpdateCommand="spUpdateRegistrantPaper" 
              UpdateCommandType="StoredProcedure"&gt;
              &lt;DeleteParameters&gt;
                  &lt;asp:Parameter Name="RegistrantId" Type="Int32" /&gt;
              &lt;/DeleteParameters&gt;
              &lt;InsertParameters&gt;
                  &lt;asp:Parameter Name="EventId" Type="Int32" /&gt;
                  &lt;asp:Parameter Name="LocalNumber" Type="Int32" /&gt;
                  &lt;asp:Parameter Name="LocalUnionEmail" Type="String" /&gt;
                  &lt;asp:Parameter Name="DistrictId" Type="Int32" /&gt;
                  &lt;asp:Parameter Name="CompletedByFirstName" Type="String" /&gt;
                  &lt;asp:Parameter Name="CompletedByLastName" Type="String" /&gt;
                  &lt;asp:Parameter Name="CompletedByPhone" Type="String" /&gt;
                  &lt;asp:Parameter Name="FirstName" Type="String" /&gt;
                  &lt;asp:Parameter Name="LastName" Type="String" /&gt;
                  &lt;asp:Parameter Name="Position" Type="String" /&gt;
                  &lt;asp:Parameter Name="Email" Type="String" /&gt;
                  &lt;asp:Parameter Name="ShirtSize" Type="String" /&gt;
                  &lt;asp:Parameter Name="Comments" Type="String" /&gt;
              &lt;/InsertParameters&gt;
              &lt;UpdateParameters&gt;
                  &lt;asp:Parameter Name="RegistrantId" Type="Int32" /&gt;
                  &lt;asp:Parameter Name="LocalNumber" Type="Int32" /&gt;
                  &lt;asp:Parameter Name="LocalUnionEmail" Type="String" /&gt;
                  &lt;asp:Parameter Name="DistrictId" Type="Int32" /&gt;
                  &lt;asp:Parameter Name="CompletedByFirstName" Type="String" /&gt;
                  &lt;asp:Parameter Name="CompletedByLastName" Type="String" /&gt;
                  &lt;asp:Parameter Name="CompletedByPhone" Type="String" /&gt;
                  &lt;asp:Parameter Name="FirstName" Type="String" /&gt;
                  &lt;asp:Parameter Name="LastName" Type="String" /&gt;
                  &lt;asp:Parameter Name="Position" Type="String" /&gt;
                  &lt;asp:Parameter Name="Email" Type="String" /&gt;
                  &lt;asp:Parameter Name="ShirtSize" Type="String" /&gt;
                  &lt;asp:Parameter Name="Comments" Type="String" /&gt;
              &lt;/UpdateParameters&gt;
          &lt;/asp:SqlDataSource&gt;
          &lt;/div&gt;
      &lt;/p&gt;
  
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p><strong>UPDATE:</strong></p>
  
  <pre><code> &lt;SelectParameters&gt;
                  &lt;asp:ControlParameter ControlID="TxtSearch" Name="FirstName" PropertyName="Text" Type="String" DefaultValue="%%" /&gt;
                  &lt;asp:Parameter Name="FirstName" Type="String" /&gt;
              &lt;/SelectParameters&gt;
  </code></pre>
  
  <p>Stored Procedure:</p>
  
  <pre><code>USE [Events2]
  GO
  /****** Object:  StoredProcedure [dbo].[spGetRegistrantPaper]    Script Date: 11/25/2015 11:10:14 AM ******/
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  
  ALTER PROCEDURE [dbo].[spGetRegistrantPaper]
      -- Add the parameters for the stored procedure here
      @FirstName nVarChar (255)
  AS
  BEGIN
      -- SET NOCOUNT ON added to prevent extra result sets from
      -- interfering with SELECT statements.
      SET NOCOUNT ON;
  
      -- Insert statements for procedure here
      SELECT LocalNumberId,
          LocalUnionEmail,
          DistrictId,
          CompletedByFirstName,
          CompletedByLastName,
          CompletedByPhone,
          FirstName,
          LastName,
          Position,
          Email,
          ShirtSize,
          Comments
          FROM Registrant
          WHERE FirstName LIKE '%' + @FirstName + '%'
  
  END
  </code></pre>