title: Using dropdownlist selected item to search gridview?
body: <p>I've got a gridview that populates from four tables, and the select command (shown below) is fully functional. I'd like to be able to search the gridview, and display only those rows whose "Status" column value is equivalent to the selected item on a dropdown list. I believe I have the select statement right for this (also listed below), but I only want the gridview to display searched results on button click. How do I make this select statement conditional? In other words, how do I make it so that the Search select statement is only used when the user clicks the search button?</p>
  
  <p>regular select statement:</p>
  
  <p><code>SelectCommand="SELECT Customer.SubId, Customer.CustName, Customer.CustCity, Customer.CustState, Broker.BroName, Broker.BroState, Broker.EntityType, Submission.Coverage, Status.Status FROM Submission INNER JOIN Broker ON Broker.SubId = Submission.SubmissionId INNER JOIN Customer ON Customer.SubId = Submission.SubmissionId INNER JOIN Status ON Status.StatusId = Submission.StatusId"</code></p>
  
  <p>my search select statement:</p>
  
  <pre><code>`SelectCommand="SELECT Customer.SubId, Customer.CustName, Customer.CustCity, Customer.CustState, Broker.BroName, Broker.BroState, 
  
  Broker.EntityType, Submission.Coverage, Status.Status FROM Submission WHERE Status = '" + Ddl.SelectedItem.Text + "' INNER JOIN Broker ON Broker.SubId = Submission.SubmissionId 
  
  INNER JOIN Customer ON Customer.SubId = Submission.SubmissionId INNER JOIN Status ON Status.StatusId = Submission.StatusId"&gt;`
  </code></pre>
  
  <p>Full gridview/droplist code:</p>
  
  <pre><code>    &lt;asp:DropDownList ID="DropDownList1" runat="server" 
              DataSourceID="SqlDataSource2" DataTextField="Status" DataValueField="Status"&gt;
  
          &lt;/asp:DropDownList&gt;
          &lt;asp:SqlDataSource ID="SqlDataSource2" runat="server" 
              ConnectionString="&lt;%$ ConnectionStrings:MyConnectionString %&gt;" 
              SelectCommand="SELECT [Status] FROM [Status]"&gt;&lt;/asp:SqlDataSource&gt;
          &amp;nbsp;&lt;asp:TextBox ID="TextBox1" runat="server"&gt;&lt;/asp:TextBox&gt;
          &amp;nbsp;
          &lt;asp:Button ID="Button1" runat="server" Text="Search" /&gt;
  &lt;/asp:Panel&gt;
      &lt;asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" 
          EmptyDataText="There are no data records to display." AllowPaging="True" 
          BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" 
          CellPadding="3" GridLines="Vertical" HorizontalAlign="Center" 
          AllowSorting="True" &gt;
          &lt;AlternatingRowStyle BackColor="#DCDCDC" /&gt;
  
          &lt;Columns&gt;
  
              &lt;asp:BoundField DataField="SubId" HeaderText="Submission Id" 
                  SortExpression="SubId" &gt;
              &lt;/asp:BoundField&gt;
              &lt;asp:BoundField DataField="CustName" HeaderText="Customer" 
                  SortExpression="CustName" /&gt;
              &lt;asp:BoundField DataField="CustCity" HeaderText="Customer City" 
                  SortExpression="CustCity" /&gt;
              &lt;asp:BoundField DataField="CustState" HeaderText="Customer State" 
                  SortExpression="CustState" /&gt;
              &lt;asp:BoundField DataField="BroName" HeaderText="Broker" 
                  SortExpression="BroName" /&gt;
              &lt;asp:BoundField DataField="BroState" HeaderText="Broker State" 
                  SortExpression="BroState" /&gt;
              &lt;asp:BoundField DataField="EntityType" HeaderText="Entity Type" 
                  SortExpression="EntityType" /&gt;
              &lt;asp:BoundField DataField="Coverage" 
                  HeaderText="Coverage" SortExpression="Coverage" /&gt;
              &lt;asp:BoundField DataField="Status" HeaderText="Status" 
                  SortExpression="Status" /&gt;
  
              &lt;asp:HyperLinkField DataNavigateUrlFields="SubId" 
                  DataNavigateUrlFormatString="View.aspx?SubId={0}" Text="View" /&gt;
              &lt;asp:HyperLinkField DataNavigateUrlFields="SubId" 
                  DataNavigateUrlFormatString="ViewEdit.aspx?SubId={0}" HeaderText="Edit" 
                  Text="Edit" /&gt;
  
          &lt;/Columns&gt;
          &lt;FooterStyle BackColor="#CCCCCC" ForeColor="Black" /&gt;
          &lt;HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" /&gt;
          &lt;PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" /&gt;
          &lt;RowStyle BackColor="#EEEEEE" ForeColor="Black" /&gt;
          &lt;SelectedRowStyle BackColor="#008A8C" Font-Bold="True" ForeColor="White" /&gt;
          &lt;SortedAscendingCellStyle BackColor="#F1F1F1" /&gt;
          &lt;SortedAscendingHeaderStyle BackColor="#0000A9" /&gt;
          &lt;SortedDescendingCellStyle BackColor="#CAC9C9" /&gt;
          &lt;SortedDescendingHeaderStyle BackColor="#000065" /&gt;
      &lt;/asp:GridView&gt;
      &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
          ConnectionString="&lt;%$ ConnectionStrings:MyConnectionString %&gt;" 
          ProviderName="&lt;%$ ConnectionStrings:ProductInstanceString.ProviderName %&gt;" 
  
  
  
          SelectCommand="SELECT Customer.SubId, Customer.CustName, Customer.CustCity, Customer.CustState, Broker.BroName, Broker.BroState, Broker.EntityType, Submission.Coverage, Status.Status FROM Submission INNER JOIN Broker ON Broker.SubId = Submission.SubmissionId INNER JOIN Customer ON Customer.SubId = Submission.SubmissionId INNER JOIN Status ON Status.StatusId = Submission.StatusId"&gt;
  
      &lt;/asp:SqlDataSource&gt;
  </code></pre>