title: Set currency for dynamic gridview cells in asp.net c#
body: <p>I have a dynamic gridview and formatting needs to be applied for certain columns.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
      {
          if (e.Row.RowType == DataControlRowType.DataRow)
          {
              for (int i = 0; i &lt; GridView1.HeaderRow.Cells.Count; i++)
              {
                  string strHeader = GridView1.HeaderRow.Cells[i].Text;
                  List&lt;string&gt; lstCurrency = new List&lt;string&gt;() { "Price", "Amount" };
                  bool checkAmount = lstCurrency.Exists(o =&gt; strHeader.Equals(o));
                  if (checkAmount)
                  {
                      e.Row.Cells[i].Text = String.Format("{0:C2}", e.Row.Cells[i].Text);
                  }
              }
          }
      } 
  </code></pre>
  
  <p>If gridview column header text contains <code>Price</code> or <code>Amount</code> then currency formatting needs to be applied and the above code doesn't work. </p>
  
  <p>Please correct me if I'm doing something wrong.</p>