title: Separate number with comma for thousands asp.net
body: <p>How do you do separate numbers with commas for every thousand on asp.net gridview (with c# in the back)</p>
  
  <p>I have been trying the following lines (individually) in the backend(nothing works, they just cut off the decimal places)</p>
  
  <pre><code>row["Applied_Amount_Varience_Sum"] = string.Format("{0:#,###0}", Convert.ToDecimal(row["Applied_Amount_Varience_Sum"]));
  row["Applied_Amount_Varience_Sum"] = Convert.ToDecimal(row["Applied_Amount_Varience_Sum"]).ToString("#,##0.00"); 
  row["Applied_Amount_Varience_Sum"] = String.Format("{0:n}", Convert.ToDecimal(row["Applied_Amount_Varience_Sum"]));
  row["Applied_Amount_Varience_Sum"] = Convert.ToDecimal(row["Applied_Amount_Varience_Sum"]).ToString("N0");
  </code></pre>
  
  <p>row is a reference to the table in the database (I am looping through each object returned and going through the rows)</p>
  
  <p>I have putting this where I bind to the gridview. So basically I right before it binds I change those attributes to have a comma but it doesn't do that</p>
  
  <p>The lines I tried will change this</p>
  
  <pre class="lang-none prettyprint-override"><code>1092.00
  </code></pre>
  
  <p>to this </p>
  
  <pre class="lang-none prettyprint-override"><code>1092
  </code></pre>
  
  <p>but I am trying to achieve this</p>
  
  <pre class="lang-none prettyprint-override"><code>1,092
  </code></pre>
  
  <p><strong>* EDIT *</strong></p>
  
  <p>This is within a template field (because I needed it to be a link with an onclick function</p>
  
  <pre class="lang-html prettyprint-override"><code>&lt;asp:TemplateField ItemStyle-HorizontalAlign="Center" HeaderText="Applied Amount Variance"&gt;
    &lt;ItemTemplate&gt;
      &lt;asp:LinkButton ID="LbPath" runat="server" 
                      Text='&lt;%# Eval("Applied_Amount_Varience_Sum") %&gt;'
                      CommandName="BindExpand" 
                      OnCommand="BindExpand"
                      CommandArgument='&lt;%#Bind("Applied_Amount_Varience_Sum") %&gt;'&gt;
      &lt;/asp:LinkButton&gt;
    &lt;/ItemTemplate&gt;
  &lt;/asp:TemplateField&gt;
  </code></pre>