Click here to Skip to main content
15,912,977 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to add separated comma in asp.net datagrid values??

This is my bind method,i need to bind a Amount with separated comma.how to do it??

if (Session["dt1"] != null) dt1 = (DataTable)Session["dt1"];
             DataRow dr = dt1.NewRow();
             dr["CusName"] = Label5.Text.Trim().ToString();//1
             dr["REP"] = Label6.Text.Trim().ToString();//2
             //Ageing
             DateTime dt = Convert.ToDateTime("2013-12-31 12:00:00.0000000"); //mm/dd/yyyy
             DateTime dt2 = Convert.ToDateTime(txtfromdate.Text);//mm/dd/yyyy
             TimeSpan ts = dt.Subtract(dt2);

             dr["AGEING"] = ts.Days.ToString();//3
             dr["DATE"] = txtfromdate.Text;//5
             dr["NUM"] = txtpaymentDetails0.Text;//6
             dr["AMOUNT"] = Double.Parse(txtamount.Text); //7

             dt1.Rows.Add(dr);
             Cusinvoicegrid.DataSource = dt1;
             Cusinvoicegrid.DataBind();
Posted
Updated 6-Dec-13 20:24pm
v2
Comments
Sergey Alexandrovich Kryukov 7-Dec-13 1:51am    
What is "separated comma"?
—SA
[no name] 7-Dec-13 1:59am    
this formt values 826,147.40
JoCodes 7-Dec-13 2:00am    
Not clear. Explanation needed.
JoCodes 7-Dec-13 2:01am    
Whats the value you are fetching from DB for amount and what format trying to display it?
[no name] 7-Dec-13 2:04am    
User Enter same values ex: 826147.40 I need to convert 826,147.40 format and bind my gridview.

1 solution

Try this, but you have to validate that it is a number first.

string str =txtamount.Text;
dr["AMOUNT"] = (string.Format("{0:C}", Convert.ToDecimal(str))).Substring(1);
 
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