title: Error Incorrect syntax near the keyword 'WHERE', checkbox list to filter Gridview
body: <p>I want to filter a grid view with checkbox list items, but I receive following error : Incorrect syntax near the keyword 'WHERE'.</p>
  
  <pre><code>&lt;asp:CheckBoxList ID="CheckBoxList1" runat="server"&gt;
              &lt;asp:ListItem&gt;MT&lt;/asp:ListItem&gt;
              &lt;asp:ListItem&gt;AT&lt;/asp:ListItem&gt;
          &lt;/asp:CheckBoxList&gt;
  </code></pre>
  
  <p>Behind code</p>
  
  <pre><code>protected void Button1_Click(object sender, EventArgs e)
          {
             DataTable dt = new DataTable();
              String strConnString = System.Configuration.ConfigurationManager.
                  ConnectionStrings["carConnectionString"].ConnectionString;
              string strQuery = "SELECT Namecar, Images,GB,Tip as finalresult FROM Cdetail3 WHERE (Ghe BETWEEN @Start AND @End) order by finalresult DESC";
              string condition = string.Empty;
              foreach (ListItem item in CheckBoxList1.Items)
              {
                  condition += item.Selected ? string.Format("'{0}',", item.Value) : string.Empty;
              }
  
              if (!string.IsNullOrEmpty(condition))
              {
                  condition = string.Format(" WHERE GB IN ({0})", condition.Substring(0, condition.Length - 1));
              }
  </code></pre>
  
  <p>I guess it is because, where of check list put after order by , but how it can be fixed !</p>
  
  <p>thanks for your help</p>