Link to home
Start Free TrialLog in
Avatar of RIAS
RIASFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Format column on datatable

Hello,
How can I  format this code on datasource

  dg(int).Columns("Total").DefaultCellStyle.Format = "N2"

Open in new window


dg is my datagridview and int is the number

instead on dg(int) how can I use datasource

Cheers
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Are you getting this from the database?

Do you want to do this in datatable? , You can do that in the query itself.
Avatar of AndyAinscow
Basically - you can't. You can format strings and store these in the databable but numbers you do that when you display them.
Avatar of RIAS

ASKER

The problem is that it is a money field.
You format the value when you display it.  (Separating data and UI in designing the app)
ASKER CERTIFIED SOLUTION
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RIAS

ASKER

Cheers Pawan!
Cheers Rias !!

Just one update..

<<SELECT * , CASE WHEN CHARINDEX('.',a,0) > 0 THEN SUBSTRING(CAST(a AS VARCHAR(10)),0,CHARINDEX('.',a,0)+3) ELSE a END FormattedColumn FROM CTE>>