title: Sorting a gridview control - The direction never changes
body: <p>I can't seem to get this right, even after looking at a few examples.</p>
  
  <p>I've got this code, which happily re-sorts my gridview in an Ascending order:</p>
  
  <pre><code>    // gridViewSorting and ConvertSortDirectionToSql are both necessary to ensure the gridview can sort when their column headers are
      //   clicked.  You must remember to add (AllowSorting="True" OnSorting="gridViewSorting") to the gridview tag on the ASP side
      protected void gridViewSorting(object sender, GridViewSortEventArgs e)
      {
         DataTable dataTable = GVInactive.DataSource as DataTable;
  
         if (dataTable != null)
         {
            DataView dataView = new DataView(dataTable);
            string SQL = "[" + e.SortExpression + "] " + ConvertSortDirectionToSql(e.SortDirection);
            dataView.Sort = SQL;
  
            GVInactive.DataSource = dataView.ToTable();
            GVInactive.DataBind();
  
         }
      }
  
      private string ConvertSortDirectionToSql(SortDirection sortDirection)
      {
          string newSortDirection = String.Empty;
  
          switch (sortDirection)
          {
              case SortDirection.Ascending:
                  newSortDirection = "DESC";
                  break;
  
              case SortDirection.Descending:
                  newSortDirection = "ASC";
                  break;
          }
  
          return newSortDirection;
      }
  </code></pre>
  
  <p>However, the second time I click on the header it's supposed to reverse the previous sorting order.  It never does.  Every time I click the header of a column, it hits the <code>case SortDirection.Ascending:</code> line and sets newSortDirection = "DESC".  The data is sorted in descending order, yet when I click the header again it resolves SortDirection to Ascending.  </p>
  
  <p>Any ideas?</p>