Click here to Skip to main content
15,923,087 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to put camas(,) between the numbers in gridview

suppose the value is 1234789 it's displayed in gridview colum 1,234,789


please share any idea to me
Posted
Comments
King Fisher 26-Nov-13 7:23am    
is this amount?
krish2013 27-Nov-13 0:31am    
Hi King_fisher,
this is amount please give any idea to me
King Fisher 27-Nov-13 0:54am    
see the solution.. doubt?
AnthonyMG 26-Nov-13 11:50am    
Did you manage to get it done with the solution provided?

You can use number formate.
Have look on below article
http://msdn.microsoft.com/en-us/library/0c899ak8.aspx#SpecifierTh[^]
 
Share this answer
 
try this sample code


XML
<asp:GridView AutoGenerateColumns="false" ID="GridView1" runat="server">

            <Columns>

                <asp:BoundField DataField="amount"  DataFormatString="{0:N}" />
            </Columns>

        </asp:GridView>




   
             DataTable dt = new DataTable();
                dt.Columns.Add("amount",typeof(double));
                dt.Rows.Add(123456789);
                dt.Rows.Add(3434);
                dt.Rows.Add(656565665);

                GridView1.DataSource = dt;
                GridView1.DataBind();
 
Share this answer
 
Custom Numeric Format Strings

This can be done using the "," Custom Specifier,[http://msdn.microsoft.com/en-us/library/0c899ak8.aspx[^]] which can be used as a number scaling specifier:

"


Group separator and number scaling


Serves as both a group separator and a number scaling specifier. As a group separator, it inserts a localized group separator character between each group. As a number scaling specifier, it divides a number by 1000 for each comma specified.

More information: The "," Custom Specifier.


Group separator specifier:

2147483647 ("##,#", en-US) -> 2,147,483,647

2147483647 ("##,#", es-ES) -> 2.147.483.647

Scaling specifier:

2147483647 ("#,#,,", en-US) -> 2,147

2147483647 ("#,#,,", es-ES) -> 2.147
 
Share this answer
 
use this to convert into amount

using System.Globalization; //namespace


System.Globalization.CultureInfo culInfo = new System.Globalization.CultureInfo("hi-IN");//globally

lbltotal.Text = amount.ToString("C", culInfo).Remove(0, 2).Trim();
 
Share this answer
 
In your row databound event of gridview firstly get value of that cell to which you want to show as comma separted
then assign it back to that cell by formatting it like below



//value=gridview cell value

value.ToString("#,#", CultureInfo.InvariantCulture)


gridview cellvalue=value;
 
Share this answer
 
v2
N or n:
Displays numeric values in number format (including group separators and optional negative sign). You can specify the number of decimal places.

DataFormatString="{0:N}"

Get More Details

system.web.ui.webcontrols.boundfield.dataformatstring
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900