title: ListView DataBind Sorting Values
body: <p>I want to have a <code>DropdownMenu</code> from which i can choose how i want to sort my <code>ListView</code>. 
  This is my current code for it :</p>
  
  <pre><code>&lt;asp:DropDownList ID="DropDownSelect" runat="server" AutoPostBack="True" 
      OnSelectedIndexChanged="GetProducts"&gt;
         &lt;asp:ListItem Selected="True" Value="DesDate"&gt; Descending Date &lt;/asp:ListItem&gt;
         &lt;asp:ListItem Value="AsDate"&gt; Ascending Date &lt;/asp:ListItem&gt;
         &lt;asp:ListItem Value="AsAlp"&gt; Ascending Alphabetical &lt;/asp:ListItem&gt;
         &lt;asp:ListItem Value="DesAlp"&gt; Decentind Alphabetical &lt;/asp:ListItem&gt;
  &lt;/asp:DropDownList&gt;
  </code></pre>
  
  <p>And I have this <code>ListView</code> to display my data:</p>
  
  <pre><code>&lt;asp:ListView ID="productList" runat="server" 
       DataKeyNames="NewsID" GroupItemCount="1"
       ItemType="SiteStiri.Models.News" SelectMethod="GetProducts"&gt;
         &lt;EmptyDataTemplate&gt;
            &lt;table&gt;
              &lt;tr&gt;
                &lt;td&gt;No data was returned.&lt;/td&gt;
              &lt;/tr&gt;
            &lt;/table&gt;
         &lt;/EmptyDataTemplate&gt;
         &lt;EmptyItemTemplate&gt;
            &lt;td/&gt;
         &lt;/EmptyItemTemplate&gt;
         &lt;GroupTemplate&gt;
            &lt;tr id="itemPlaceholderContainer" runat="server"&gt;
                &lt;td id="itemPlaceholder" runat="server"&gt;&lt;/td&gt;
            &lt;/tr&gt;
         &lt;/GroupTemplate&gt;
         &lt;ItemTemplate&gt;
            &lt;td runat="server"&gt;
         &lt;table&gt;
            &lt;tr&gt;
              &lt;td&gt;
                &lt;a href="NewsDetails.aspx?newsID=&lt;%#:Item.NewsID%&gt;"&gt;
                   &lt;img src="/Catalog/Images/Thumbs/&lt;%#:Item.ImagePath%&gt;"
               width="100" height="75" style="border: solid" /&gt;&lt;/a&gt;
             &lt;/td&gt;
           &lt;/tr&gt;
           &lt;tr&gt;
             &lt;td&gt;
              &lt;a href="NewsDetails.aspx?newsID=&lt;%#:Item.NewsID%&gt;"&gt;
                 &lt;p style="color: black;"&gt;
                    &lt;%#:Item.NewsTitle%&gt;
                 &lt;/p&gt;
              &lt;/a&gt;
            &lt;/td&gt;
           &lt;/tr&gt;
           &lt;tr&gt;
             &lt;td&gt;&amp;nbsp;&lt;/td&gt;
           &lt;/tr&gt;
         &lt;/table&gt;
        &lt;/p&gt;
       &lt;/td&gt;
       &lt;/ItemTemplate&gt;
       &lt;LayoutTemplate&gt;
         &lt;table style="width:100%;"&gt;
            &lt;tbody&gt;
              &lt;tr&gt;
                &lt;td&gt;
                 &lt;table id="groupPlaceholderContainer" runat="server" 
                      style="width:100%"&gt;
                   &lt;tr id="groupPlaceholder"&gt;&lt;/tr&gt;
                 &lt;/table&gt;
                 &lt;/td&gt;
                &lt;/tr&gt;
               &lt;tr&gt;
             &lt;td&gt;&lt;/td&gt;
            &lt;/tr&gt;
           &lt;tr&gt;&lt;/tr&gt;
        &lt;/tbody&gt;
       &lt;/table&gt;
       &lt;/LayoutTemplate&gt;
    &lt;/asp:ListView&gt;
  </code></pre>
  
  <p>The thing that i have no idea how to do is:
   After selecting a sorting rule from the dropdown menu, i can't figure out how to write(or where to write) the method that would update my ListView as it should. My attemp is :</p>
  
  <pre><code> public IQueryable&lt;News&gt; GetProducts()
          {
              var _db = new SiteStiri.Models.NewsContext();
              IQueryable&lt;News&gt; query = _db.News;
  
              if (("DesDate").Equals(DropDownSelect.SelectedItem.Value))
              {
                  query.OrderByDescending(u =&gt; u.ReleaseDate);
              }
              if (("AsDate").Equals(DropDownSelect.SelectedItem.Value))
              {
                  query.OrderBy(u =&gt; u.ReleaseDate);
              }
              if (("AsAlp").Equals(DropDownSelect.SelectedItem.Value))
              {
                  query.OrderBy(u =&gt; u.NewsTitle);
              }
              if (("DesApl").Equals(DropDownSelect.SelectedItem.Value))
              {
                  query.OrderByDescending(u =&gt; u.NewsTitle);
              }
  
  
              return query;
          }
  </code></pre>
  
  <p>which gives me a bunch of errors and it doesn't even work .... a little bit of help please? I am new to this (2 days).</p>