title: How to change orderby on postback for LINQ to SQL query
body: <p>I have a drop down list set to auto post back which needs to return a list of products in the specified order. I thought I could just put that query in its own method and use a parameter to specify the orderby, but I cannot get it to work.</p>
  
  <p>Here is an example:</p>
  
  <pre><code>protected void Show_Products(int item)
      {
          using (storeDataContext db = new storeDataContext())
          {
             string query = "";
              switch (item)
              {
                  case 1:
                      query ="x.Name";
                      break;
                  case 2:
                      query = "x.MSRP";
                      break;
                  default:
                      break;
              }
              var q = db.Items.OrderBy(x=&gt; query).Select(x =&gt; x);
              foreach(var n in q)
               {
                 Do work
               }
             }
         }
  </code></pre>
  
  <p>And the drop down list method that gets called on postback:</p>
  
  <pre><code>protected void ddlSortBy_SelectedIndexChanged(object sender, EventArgs e)
      {
          int value =int.Parse(ddlSortBy.SelectedValue);
          Show_Products(value);
      }
  </code></pre>