Click here to Skip to main content
15,908,013 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi developers,


how to add comma to numbers in gridview.please help me its urgent.
presently i conveting to decimal using math.round method and getting like this.(50000)

but i need like this-50,000

sorry for grammer mistakes

Regards
Aravind
Posted
Updated 7-Apr-12 2:47am
v2
Comments
[no name] 7-Apr-12 8:48am    
Don't ask for urgent help, it is rude. It may be urgent to you but no one else here. This is a volunteer site and people will answer on their time, not yours.
Nilesh Patil Kolhapur 7-Apr-12 8:54am    
u can manually change it before binding to grid view

Formatting can be allied with your databinding expression.

Try reading the documentation
http://msdn.microsoft.com/en-us/library/2d76z3ck.aspx[^]
 
Share this answer
 
Wow! You have accepted probably the worst solution. No, here is the good one:
Displaying number in thousands format[^].

—SA
 
Share this answer
 
C#
#region FormatNumber
     public string FormatNumber(string strNumber)
     {
         string test;
         try
         {
             if (strNumber.Length == 1)
             {
                 return strNumber;
             }
             else if (string.Compare(strNumber, "0", false) == 0)
             {
                 return strNumber;
             }
             else if (strNumber.Length == 2)
             {
                 return strNumber;
             }
             else if (strNumber.Length == 3)
             {
                 return strNumber;
             }
             else if (strNumber.Length == 4)
             {
                 return strNumber.Substring(0,1)+","+strNumber.Substring(1);
             }
             else if (strNumber.Length == 5)
             {
                 return strNumber.Substring(0, 2) + "," + strNumber.Substring(2);
             }
             else if (strNumber.Length == 6)
             {
                test= strNumber.Substring(0, 3) + "," + strNumber.Substring(3);
                return test;
             }
             else if (strNumber.Length == 7)
             {
                 return strNumber.Substring(0, 1) + "," + strNumber.Substring(1, 3) + "," + strNumber.Substring(4);
             }
             else if (strNumber.Length == 8)
             {
                 return strNumber.Substring(0, 2) + "," + strNumber.Substring(2, 3) + "," + strNumber.Substring(5);
             }
             else if (strNumber.Length == 9)
             {
                 return strNumber.Substring(0, 3) + "," + strNumber.Substring(3, 3) + "," + strNumber.Substring(6);
             }
             else if (strNumber.Length == 10)
             {
                 return strNumber.Substring(0, 1) + "," + strNumber.Substring(2, 3) + "," + strNumber.Substring(4, 3) + "," + strNumber.Substring(7);
             }
             else if (strNumber.Length == 11)
             {
                 return strNumber.Substring(0, 2) + "," + strNumber.Substring(2, 3) + "," + strNumber.Substring(5, 3) + "," + strNumber.Substring(8);
             }
             else if (strNumber.Length == 12)
             {
                 return strNumber.Substring(0, 3) + "," + strNumber.Substring(3, 3) + "," + strNumber.Substring(6, 3) + "," + strNumber.Substring(9);
             }
             else
             {
                 return "false";
             }
         }
         catch (NullReferenceException nullex)
         {
             objError.LoggerError(nullex);
             lblErrorMessage.Text = nullex.Message;
             return "FALSE";
         }
         catch (SqlException sqlex)
         {

             objError.LoggerError(sqlex);
             lblErrorMessage.Text = sqlex.Message;
             return "FALSE";
         }
         catch (Exception ex)
         {
             objError.LoggerError(ex);
             lblErrorMessage.Text = ex.Message;
             return "FALSE";
         }

     }


     #endregion


this is the solution i for comma b/w numbers......
 
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