title: How can I Format the gridview column to display 2 decimalplaces from code behind?
body: <p>I am trying to format my Gridview columns to display decimal values upto 2 places after the decimal point. 
  I am aware of both <code>DataFormatString='{0:0.00}</code> for the boundfield and also <code>Eval("NumFailedFiles", "{0:0.00}")</code> for ItemTemplate.</p>
  
  <p>But i want this to be configurable, i.e. i want to get the no. of decimal places from the database and apply to the boundfield or itemtemplate. 
  For acheiving this i have tried formatting in gridview_RowDataBound Event but in vain.</p>
  
  <pre><code> GridDecimal = Convert.ToInt32(resXResourceSet.GetString("GridMaxDecimals"));
          var field = gridView.Columns[1] as BoundField;
          field.DataFormatString = "{0:0.00}";
  </code></pre>
  
  <p>With this code i am encountering an exception which says </p>
  
  <blockquote>
    <p>"Object reference not set to an instance of an object"</p>
  </blockquote>
  
  <p>at the 3rd line of the above code.</p>
  
  <p>Can someone help me on how to achieve this for both boundfield and Itemtemplate</p>
  
  <p>This is my datasource to clear the ambiguity</p>
  
  <p>My data source:
  <img src="https://i.stack.imgur.com/8EbSy.png" alt=""></p>