Sorting gridview bound to datatable in c#.net
<p>I have a gridview which is bound to a DataTable.  When I try to sort the gridview, it goes blank.  How can I enable sorting this gridview?</p>

<p>I know this question has been asked before, but what I'm looking for is an <em>explanation</em> of how to do it.  Perhaps with a simple example.  </p>

<p>I have read that I need to put some code in the on_sorting and/or on_sorted events, but I don't understand what needs to go there.  </p>

<p>Again, I want to understand the method of accomplishing this, I don't just want a giant block of code.</p>

<hr>

<p>Ok, here's what I have now, but still not working:</p>

<pre><code>            &lt;asp:GridView ID="gridResults" runat="server" CellPadding="4" ForeColor="#333333"
            GridLines="Horizontal" AllowSorting="True" AllowPaging="True" 
            EmptyDataText="No Tracking Information Found for the given criteria." 
            PageSize="15" onsorted="gridResults_Sorted" AutoGenerateColumns="False" 
            EnableSortingAndPagingCallbacks="True"&gt;
            &lt;RowStyle BackColor="#E3EAEB" /&gt;
            &lt;FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /&gt;
            &lt;PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" /&gt;
            &lt;SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" /&gt;
            &lt;HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" /&gt;
            &lt;EditRowStyle BackColor="#7C6F57" /&gt;
            &lt;AlternatingRowStyle BackColor="White" /&gt;
        &lt;/asp:GridView&gt;
</code></pre>

<p>And then in code behind:</p>

<pre><code>  //From search method
gridResults.Columns.Clear();
    foreach (DataColumn col in currentResults.Columns)
    {
        String fieldName = col.ColumnName;
        BoundField field = new BoundField();
        field.DataField = fieldName;
        field.SortExpression = fieldName;
        field.HeaderText = fieldName;

        gridResults.Columns.Add(field);  
    }

    gridResults.DataSource = currentResults;
    gridResults.DataBind();
    gridResults.AllowSorting = true;
</code></pre>

<p>Can anyone see what I'm still missing?  Results show, but no sorting or paging works.</p>
