Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
Hi all...i want to limit the decimal length of a datagridview column..
 
Please help me out
Posted 16-Nov-12 23:28pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

try this
for 2 places of decimal
 
double.Parse(string.Format("{0:0.00}", Eval("Name").ToString()))
 
or
 
double.Parse(Eval("Name").ToString()).ToString("0.00")
  Permalink  
Comments
DileepkumarReddy at 17-Nov-12 6:12am
   
what is Eval and in which event should i try this...
pryashrma at 17-Nov-12 6:59am
   
are you asking the query for 'GridView' control
DileepkumarReddy at 17-Nov-12 7:14am
   
yes
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Alternate and easy way:
set the DataFormatString of Databound field
Format: {0:F}
1234.567 -> 1234.57
Format: {0:F3}
1234.567 -> 1234.567
 
for eg:
DataFormatString ="{0:F3}"
 
in aspx page design mode
single click on gridView1
then click on ">" of gridView1
then click on 'Edit Columns'
then select respective field and set 'DataFormatString'
 
you can also view the following link
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.boundfield.dataformatstring.aspx
 
please tell me if i m confusing you
  Permalink  
Comments
DileepkumarReddy at 17-Nov-12 7:04am
   
Actually i am working on windows app.
There is no property DataFormatString..
pryashrma at 17-Nov-12 7:57am
   
does this line help you-
 
this.dataGridView1.Columns["UnitPrice"].DefaultCellStyle.Format = "F3";
pryashrma at 17-Nov-12 7:48am
   
sorry can't help
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Hey there,
Had a similar issue a while back...
 
VB Code to limit decimal:
Me.DataGridView1.Columns.Item(3).DefaultCellStyle.Format = "n2"
 
C# Code:
dataGridView2.Columns["Column_Name"].DefaultCellStyle.Format = "n2";
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 385
1 Maciej Los 180
2 Tino Fourie 132
3 Richard MacCutchan 115
4 arvind mepani 104


Advertise | Privacy | Mobile
Web03 | 2.8.140709.1 | Last Updated 19 Jun 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid