Click here to Skip to main content
15,881,812 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am running a query which will give a amount as string and now i need to show the string with comma seperators when population in the grid view and in the text box.


this is my code




when i add .tostring("N") it is throwing error kindly guide

and i have no clue how to show it with commas in grid view

What I have tried:

C#
txtbudamt.Text = drContract["Budget_Amount"].ToString();
Posted
Updated 23-Dec-20 19:01pm
v2
Comments
CHill60 28-Oct-20 11:54am    
Firstly, if an error is thrown it is helpful to share with us exactly what that error is.
What is drContract?
Does it have an element "Budget_Amount"?
Member 13998042 28-Oct-20 12:40pm    
i am really sorry , i came over that error , now i need to show a string value (1000000.00) the decimal will stored like a string in the db, i need to show this string with comma separator while showing in grid view
CHill60 29-Oct-20 5:43am    
Don't store decimals as strings, then you can use standard formatting techniques
Jo_vb.net 28-Oct-20 16:54pm    
This link may help:
https://docs.microsoft.com/en-us/dotnet/api/system.globalization.numberformatinfo.numberdecimalseparator?redirectedfrom=MSDN&view=netcore-3.1#System_Globalization_NumberFormatInfo_NumberDecimalSeparator
BillWoodruff 28-Oct-20 19:05pm    
show a clear example of the string you want to convert, and an example of how you want that string to be formatted. the commas go where ?

1 solution

Try Formatting the Data using a StringBuilder to concat your string data and commas or String.Format something like the given solutions below:

1.
StringBuilder strData = new StringBuilder();
txtbudamt.Text = strData.Append(Convert.ToString(drContract["Budget_Amount"]) + ",").ToString();

2.
txtbudamt.Text = drContract["Budget_Amount"].ToString().Format("ExpressionFormat");
 
Share this answer
 

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