title: Sorting is not working on gridview
body: <p>I added a sorting option in a GridView, but don't know why it isn't working.</p>
  
  <p>This is my markup:</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1"  AllowSorting="true" runat="server" Width="100%"
      AutoGenerateColumns="False" DefaultSortDirection="Ascending" DataKeyNames="ClientAccountNumber,Invoice" AllowPaging="true"OnSorting="GridView1_Sorting"&gt;
   &lt;Columns&gt;
  &lt;asp:TemplateField HeaderText="Invoice" HeaderStyle-HorizontalAlign="Left" ItemStyle-HorizontalAlign="Left" SortExpression="[Invoice]"&gt;
         &lt;ItemTemplate&gt;
        &lt;asp:Label ID="lblInvoice" runat="server" Text='&lt;%# Eval("Invoice")%&gt;'&gt;&lt;/asp:Label&gt;
                &lt;/ItemTemplate&gt;
          &lt;/asp:TemplateField&gt;    
  &lt;/Columns&gt;
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
  {
     // bindGrid();
  
      DataTable dataTable = GridView1.DataSource as DataTable;
      if (dataTable != null)
      {
          DataView dataView = new DataView(dataTable);
          dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);
          GridView1.DataSource = dataView;
          GridView1.DataBind();
      }
  }
  </code></pre>
  
  <p>Code for binding the gridview</p>
  
  <pre><code>private void bindGrid()
  {
      try
      {
          if (int.Parse(lblAccountNo.Text.ToString()) &gt; 0)
          {
              _clientTransection.AccountNo  =Convert.ToInt32(lblAccountNo.Text.ToString());
             Collection&lt;ClientTransInvoiceRows&gt; _clientList =    _clientTransection.Execute();
             GridView1.DataSource = _clientList;
             GridView1.DataBind();
          }
      }
      catch
      {
      }
  }
  </code></pre>
  
  <p>This line:</p>
  
  <pre><code>DataTable dataTable = GridView1.DataSource as DataTable;
  </code></pre>
  
  <p>is giving me null. Is there another option for sorting my GridView?</p>