title: sort Gridview doesn't work
body: <p>I have asp.net page contain gridview as following </p>
  
  <pre><code>&lt;asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
                      OnPageIndexChanging="gridView_PageIndexChanging" 
                      OnSorting="TaskGridView_Sorting"
                      AllowSorting="True"  AutoGenerateColumns="False" 
                      onselectedindexchanged="GridView1_SelectedIndexChanged" 
                      BackColor="#DEBA84" BorderColor="#DEBA84" BorderStyle="None" BorderWidth="1px" 
                      CellPadding="3" CellSpacing="2"&gt;
                      &lt;RowStyle BackColor="#FFF7E7" ForeColor="#8C4510" /&gt;
                      &lt;Columns&gt;
                        &lt;asp:boundfield datafield="name_english" convertemptystringtonull="true" headertext="Name"/&gt;
                          &lt;asp:BoundField DataField="Inc_ID" convertemptystringtonull="true" HeaderText="Inc_ID" SortExpression="Inc_ID"/&gt;
                          &lt;asp:BoundField DataField="UID" HeaderText="Study_UID" SortExpression= "UID"/&gt;
                      &lt;/Columns&gt;
                      &lt;FooterStyle BackColor="#F7DFB5" ForeColor="#8C4510" /&gt;
                      &lt;PagerStyle ForeColor="#8C4510" HorizontalAlign="Center" /&gt;
                      &lt;SelectedRowStyle BackColor="#738A9C" Font-Bold="True" ForeColor="White" /&gt;
                      &lt;HeaderStyle BackColor="#A55129" Font-Bold="True" ForeColor="White" /&gt;
                  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>I fill and sort it using the following code </p>
  
  <pre><code>        protected void Button1_Click(object sender, EventArgs e)
          {
              //connection to database 
              string connection = System.Configuration.ConfigurationManager.ConnectionStrings["NorthindConnectionString"].ConnectionString;
              SqlConnection myConn = new SqlConnection(connection);
              myConn.Open();
              SqlCommand cmd = new SqlCommand(" WorkList", myConn);
              cmd.CommandType = CommandType.StoredProcedure;
              cmd.Parameters.Add(new SqlParameter("@Name", TextBox1.Text));
              cmd.Parameters.Add(new SqlParameter("@ID", TextBox2.Text)); 
              cmd.Parameters.Add(new SqlParameter("@AccNo", TextBox4.Text)); 
  
  
              SqlDataAdapter da = new SqlDataAdapter(cmd);
              DataSet ds = new DataSet();
              da.Fill(ds);
              GridView1.DataSource = ds;
              GridView1.DataBind();
  
              Session["TaskTable"] = ds.Tables[0]; 
  
              ds.Dispose();
              da.Dispose();
              GridView1.Visible = true;
  
              myConn.Close();
  
  
          }
   protected void TaskGridView_Sorting(object sender, GridViewSortEventArgs e)
          {
  
              //Retrieve the table from the session object.
              DataTable dt = Session["TaskTable"] as DataTable;
  
              if (dt != null)
              {
  
                  //Sort the data.
                  dt.DefaultView.Sort = e.SortExpression + " " + GetSortDirection(e.SortExpression);
                  GridView1.DataSource = Session["TaskTable"];
                  GridView1.DataBind();
              }
  
          }
  
  
  
          private string GetSortDirection(string column)
          {
  
              // By default, set the sort direction to ascending.
              string sortDirection = "ASC";
  
              // Retrieve the last column that was sorted.
              string sortExpression = ViewState["SortExpression"] as string;
  
              if (sortExpression != null)
              {
                  // Check if the same column is being sorted.
                  // Otherwise, the default value can be returned.
                  if (sortExpression == column)
                  {
                      string lastDirection = ViewState["SortDirection"] as string;
                      if ((lastDirection != null) &amp;&amp; (lastDirection == "ASC"))
                      {
                          sortDirection = "DESC";
                      }
                  }
              }
  
              // Save new values in ViewState.
              ViewState["SortDirection"] = sortDirection;
              ViewState["SortExpression"] = column;
  
              return sortDirection;
          }
  
  
      }
  </code></pre>
  
  <p>the problem when click on any header for sorting raise error  System.IndexOutOfRangeException: Cannot find column name ..   , any idea to solve that , I am sure from the columns name in database , </p>