Click here to Skip to main content
15,892,697 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi I want to format the string of column of gridview . the type of data field is NvarChar
i want to display e.g 123456 as 123,456
please help me
I try this code:
C#
if (e.Row.RowType == DataControlRowType.DataRow)
        {
          
            e.Row.Cells[4].Text = String.Format((e.Row.Cells[4].Text), "#,##");
           
        }


but the error :
the name "strings"does not exist in the current contex

What I have tried:

how to Format string of column of gridview with Thousand Seperator in asp.net c#
Posted
Updated 8-Mar-21 23:46pm
v2

You may try with:
C#
String.Format

instead. There is no Strings class.
 
Share this answer
 
Comments
rezaeti 5-Apr-16 9:26am    
hi thanks
I try but code dont work
if (e.Row.RowType == DataControlRowType.DataRow)
{

e.Row.Cells[4].Text = String.Format((e.Row.Cells[4].Text), "#,##0.00");

}
phil.o 5-Apr-16 9:33am    
decimal result;
if (decimal.TryParse(e.Row.Cells[4].Text, out result)) {
e.Row.Cells[4].Text = String.Format("{0:#,##0.00}", result);
}
rezaeti 5-Apr-16 9:39am    
I have a question about stimulsoft do you can help me
rezaeti 5-Apr-16 9:37am    
so thanks it work
rezaeti 5-Apr-16 9:37am    
very thanks
Hi,

In addition to phil.o's comment.

Have a look at the manual for Decimal.ToString Method (String) (System)[^]

You can then use it like:
C#
decimal result;
if (e.Row.RowType == DataControlRowType.DataRow)
{
    if (decimal.TryParse(e.Row.Cells[4].Text, out result)) {
         e.Row.Cells[4].Text = result.ToString("0,0");
    }
}


... hope it helps.
 
Share this answer
 
// Right Align Decimal Fields in GridView Row
decimal result;
for (int i = 1; i < e.Row.Cells.Count; i++)
{
if (decimal.TryParse(e.Row.Cells[i].Text, out result))
{
e.Row.Cells[i].HorizontalAlign = HorizontalAlign.Right;
}
}
 
Share this answer
 
Comments
CHill60 9-Mar-21 7:13am    
Nothing to do with the original question!

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