title: dot net gridview sorting problem
body: <p>I have a web application (with C#). I have a GridView and want to be able to sort its contents. I have added the tags</p>
  
  <p>...</p>
  
  <pre><code>AllowSorting="True"
  onsorting="MyGridView_Sorting"&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>asp:BoundField DataField="NAME" HeaderText="Name" SortExpression="NAME" 
  </code></pre>
  
  <p>inside the GridView. I have implemented the MyGridView_Sorting method. Thing is: it does not work. Does nothing. The header text "Name" looks like an active link, but clicking produces no effect. Putting a break point inside </p>
  
  <pre><code>MyGridView_Sorting
  </code></pre>
  
  <p>shows that it actually never goes inside the function. What is wrong? What do I miss?</p>
  
  <p>Thanks!!!</p>
  
  <p>Sep</p>
  
  <pre><code>&lt; asp:GridView ID="MyGridView"
  runat="server"                               
  CssClass="pvgrid" 
  Width="90%" 
  AutoGenerateColumns="false"
  OnRowCommand="MyGridView_RowCommand"
  AllowPaging="True" 
  PageSize="10" 
  AllowSorting="True"
  onsorting="MyGridView_Sorting" 
  onpageindexchanging="MyGridView_PageIndexChanging" &gt;
  
  &lt; Columns &gt;
  &lt; asp:BoundField DataField="NAME" HeaderText="Name" SortExpression="NAME"  /&gt;
  &lt; /Columns &gt;
  &lt; /asp:GridView &gt;
  
  
  protected void MyGridView_PageIndexChanging(object sender, GridViewPageEventArgs e)
  {
      MyGridView.PageIndex = e.NewPageIndex;
      MyGridView.DataBind();
  }
  
  protected void MyGridView_Sorting(object sender, GridViewSortEventArgs e)
  {
      DataTable dataTable = MyGridView.DataSource as DataTable;
  
      if (dataTable != null)
      {
          DataView dataView = new DataView(dataTable);
          dataView.Sort = e.SortExpression + " "+ ConvertSortDirectionToSql(e.SortDirection);
          MyGridView.DataSource = dataView;
          MyGridView.DataBind();
      }
  }
  </code></pre>