title: System.IndexOutOfRangeException: Cannot find column
body: <p>I am implementing gridview sorting which is part of a user control. Below code gives me Indexoutofrange error.</p>
  
  <p>The error message is at </p>
  
  <pre><code>dtView.Sort = strSort;
  </code></pre>
  
  <p>Errormessage:</p>
  
  <blockquote>
    <p>System.IndexOutOfRangeException: Cannot find column TEXT_COUNTY_ID.</p>
  </blockquote>
  
  <p>Can anyone point out what I am doing wrong?</p>
  
  <pre><code>protected void SortGridData_Hkl(Object sender, GridViewSortEventArgs e)
      {
          GridView _dgd_work_onoff = (GridView)Page.FindControl("bodyuc$dgd_work_onoff");
          DataSet dstemp;
          DataView dtView;
          if (ViewState["dsfetchResults"] != null)
          {
              dstemp = (DataSet)ViewState["dsfetchResults"];
              string strSortOrder = ViewState["SortOrder"].ToString();
  
              if (strSortOrder == "DESC")
              {
                  strSortOrder = "ASC";
                  ViewState["SortOrder"] = strSortOrder;
              }
              else
              {
                  strSortOrder = "DESC";
                  ViewState["SortOrder"] = strSortOrder;
              }
  
              string strSort = e.SortExpression.ToString() + " " + strSortOrder;
              ViewState["SortString"] = strSort;
  
              dtView = dstemp.Tables[0].DefaultView;
  
              dtView.Sort = strSort;
              if (dtView.Count != 0)
              {
                  if (_dgd_work_onoff != null)
                  {
                      _dgd_work_onoff.DataSource = dtView;
                      _dgd_work_onoff.DataBind();
                  }
              }
  
  
          }
  </code></pre>
  
  <p>'dsfetchResults' is suppose to contain the data from the database.</p>