title: Change Datafield of Telerik RadGrid GridBoundColumn using C#
body: <p>I have a RadGrid which is initialised in markup:</p>
  
  <pre><code>&lt;telerik:RadGrid runat="server" ID="GridViewSelector" SkinID="GridViewSelectorSkin" AllowPaging="True" PageSize="12" AllowSorting="True" EnableViewState="true" 
      AllowCustomPaging="true" AllowFilteringByColumn="true" DataKeyNames="ID" AutoGenerateColumns="False" ShowFooter="false" style="float:left;"
      AllowMultiRowEdit="false" OnNeedDataSource="GridViewSelector_NeedDataSource"
      OnItemCommand="GridViewSelector_ItemCommand" EnableEmbeddedSkins="false" OnItemCreated="GridViewSelector_ItemCreated"
      OnSortCommand="GridViewSelector_SortCommand" 
      OnItemDataBound="GridViewSelector_ItemDataBound" 
      OnPreRender="GridViewSelector_PreRender" OnSelectedIndexChanged ="GridViewSelector_SelectedIndexChanged"&gt;
      &lt;PagerStyle Visible="false" /&gt;
      &lt;ClientSettings EnableRowHoverStyle="true"&gt;
          &lt;Selecting AllowRowSelect="false" /&gt;
      &lt;/ClientSettings&gt;
      &lt;MasterTableView runat="server" AllowMultiColumnSorting="false" AllowNaturalSort="false" DataKeyNames="ID"&gt;
          &lt;SortExpressions&gt;
              &lt;telerik:GridSortExpression FieldName="ExpenseDate" SortOrder="Ascending"  /&gt;
          &lt;/SortExpressions&gt;
          &lt;Columns&gt;
              &lt;telerik:GridButtonColumn ButtonType="ImageButton" ImageUrl="~/Images/ListingDown.png" CommandName="Select"&gt;                 
                  &lt;HeaderStyle HorizontalAlign="Center" Width="50px" /&gt;
                  &lt;ItemStyle HorizontalAlign="Center" Width="50px" /&gt;                    
              &lt;/telerik:GridButtonColumn&gt;
              &lt;telerik:GridBoundColumn HeaderText="Date" UniqueName="ExpenseDate"  DataField="ExpenseDate" SortExpression="ExpenseDate" HtmlEncode="false"&gt;
                  &lt;HeaderStyle HorizontalAlign="Center" Width="100px" /&gt;
                  &lt;ItemStyle HorizontalAlign="Center" Width="100px" /&gt;
              &lt;/telerik:GridBoundColumn&gt;
              &lt;telerik:GridBoundColumn HeaderText="Type" UniqueName="ExpenseType" DataField="Type" SortExpression="Type" HtmlEncode="false"&gt;
                  &lt;HeaderStyle HorizontalAlign="Center" Width="100px" /&gt;
                  &lt;ItemStyle HorizontalAlign="Center" Width="100px" /&gt;
              &lt;/telerik:GridBoundColumn&gt;
              &lt;telerik:GridBoundColumn HeaderText="Description" UniqueName="ExpenseDescription" DataField="Description" SortExpression="Description"&gt;
                  &lt;HeaderStyle HorizontalAlign="Center" /&gt;
              &lt;/telerik:GridBoundColumn&gt;
              &lt;telerik:GridBoundColumn HeaderText="Gross" UniqueName="Gross" DataField="Gross" SortExpression="Gross" HtmlEncode="false"&gt;
                  &lt;HeaderStyle HorizontalAlign="Center" Width="100px" /&gt;
                  &lt;ItemStyle HorizontalAlign="Center" Width="100px" /&gt;
              &lt;/telerik:GridBoundColumn&gt;
              &lt;telerik:GridBoundColumn HeaderText="" UniqueName="" DataField="" SortExpression="" HtmlEncode=""&gt;
                  &lt;HeaderStyle HorizontalAlign="Center" Width="100px" /&gt;
                  &lt;ItemStyle HorizontalAlign="Center" Width="100px" /&gt;
              &lt;/telerik:GridBoundColumn&gt;               
          &lt;/Columns&gt;
      &lt;/MasterTableView&gt;
  &lt;/telerik:RadGrid&gt;
  </code></pre>
  
  <p>When a user clicks on a tab I reformat the same RadGrid control in the .aspx.cs file. Here is an example:</p>
  
  <pre><code>                cols[1].HeaderText = "Claim No.";
                  cols[1].DataType = typeof(System.Int64);
                  ((GridBoundColumn)cols[1]).DataField = "ClaimNumber";
  
  
                  cols[2].HeaderText = "Claimant";
                  cols[2].DataType = typeof(System.String);
                  ((GridBoundColumn)cols[2]).DataField = "Claimant";
  
  
                  cols[3].HeaderText = "Date";
                  cols[3].DataType = typeof(System.DateTime);
                  ((GridBoundColumn)cols[3]).DataField = "ExpenseDate";
                  ((GridBoundColumn)cols[3]).DataFormatString = "{0:" + HttpHelper.User.PreferredDateFormat + "}";
  
                  cols[4].HeaderText = "Description";
                  cols[4].DataType = typeof(System.String);
                  ((GridBoundColumn)cols[4]).DataField = "ClaimNumber";
  
  
                  cols[5].HeaderText = "Amount";
                  cols[5].DataType = typeof(System.Decimal);
                  ((GridBoundColumn)cols[5]).DataField = "Amount";
                  ((GridBoundColumn)cols[5]).HeaderStyle.Width = 100;
                  ((GridBoundColumn)cols[5]).ItemStyle.Width = 100;
  </code></pre>
  
  <p>This almost works perfectly except for one problem. A column which seems to have sorting applied to it doesn't populate with the data. In particular from above the following isn't working:</p>
  
  <pre><code>((GridBoundColumn)cols[1]).DataField = "ClaimNumber";
  </code></pre>
  
  <p>Previously it is populated with a date (dd/mm/yyyy) which has a sort expression applied to it. All other fields (which had no sort expression previously)   are rebound and display the correct data.</p>
  
  <p>Anyone else experienced this?</p>