title: Setting Parameter fields dynamically for a SqlDataSource
body: <p>I need to fill in the "SelectParameters" dynamically , but all I found on Google , was using fixed parameters.</p>
  
  <pre><code>&lt;asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="XX"
                              OnSelecting="SqlDataSource2_Selecting" SelectCommand=""&gt;
                              &lt;SelectParameters&gt;
                              &lt;/SelectParameters&gt;
                          &lt;/asp:SqlDataSource&gt;
  </code></pre>
  
  <p>Is there any solutions ?</p>
  
  <p>I also tried to use the "OnSelecting" event , but I can't assign value to parameters that are not present.   </p>
  
  <pre><code> protected void SqlDataSource2_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
      {
          string[] queryFields = new string[] { ... }; // some dynamic field depends on different table
  
          foreach (string s in queryFields)
          {
              e.Command.Parameters["@" + s].Value = "filter";
          }
  
      }
  </code></pre>