Click here to Skip to main content
15,900,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am retrieving data from SQL Server to a grid view in ASP.Net. Below is the grid view after I retrieved the data from the database.

C#
Time   | City_1    | City_2   | City_3
02/12  | 30000000  |12000000  |55000000000
02/12  | 14000000  |1000000   |7200000000  


So I want the values in the grid view to be divided by 1000000(one million) and put "mil" after it. After dividing it, I also want to put a comma in every thousandth place of the remainder value for the ease of the user.
So my grid view will look like this after formatting.
C#
Time   | City_1 | City_2  | City_3
02/12  | 30mil  | 12mil   | 55,000mil
02/12  | 14mil  | 1mil    | 7,200mil  


What I have tried:

Below is the code how I am retrieving the data from SQL Server to the grid view.
SqlConnection con = new SqlConnection("My Connection");

string s = "My Stored Procedure";

con.Open();
SqlDataAdapter da = new SqlDataAdapter(s, con);
DataSet ds = new DataSet();

da.Fill(ds);

gridView1.DataSource = ds;
gridView1.DataBind();

con.Close();
Posted
Updated 8-Aug-18 17:22pm
v2
Comments
ZurdoDev 8-Aug-18 8:16am    
1. Divide by 1M in SQL.
2. Format in client side.
Member 13863605 8-Aug-18 11:26am    
I want to do it in grid view not SQL
ZurdoDev 8-Aug-18 11:29am    
Then you'll have to use the event where each row is created. Refer to documentation.

1 solution

Add "calculated columns" to your grid view (and drop the "raw" columns):

c# - Add calculated column to a GridView - Stack Overflow[^]
 
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