C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » ASP.NET/Web Applications »

Format Date, numeric values in the DataGrid.


Posted Date: 30 Apr 2004    Resource Type: Articles    Category: ASP.NET/Web Applications
Author: ManojRajanMember Level: Gold    
Rating: 1 out of 5Points: 10



Introduction


There are two ways to modify the format of the data in a datagrid. One is through the design view. Right click on the data grid and select Property Builder and select the Column view, under the selected column select the desired column for which you wan to set the format. Then Under the Bound Column Properties section set the data formatting expression value to the desired format the selected column.

The other way to do is to edit the HTML of the page and add the dataformatstring attribute in the BoundColumn tag of the desired column.

The Format expressions are as follows: -

1. This will display a text Price: followed by the numeric text in currency format

Data Format String value : Price: {0:C}

NOTE : THE ABOVE MENTIONED FORMAT IS USING A ZERO IT IS NOT THE ALPHABET O

Applied to numeric and decimal data types.

The currency format is according to the culture info set in the web config file.

2. Integers are displayed in a zero-padded field four characters wide.

Data Format String value : {0:D4}

Applied to integer datatype only.

3. To show two decimal places followed by "%"

Data Format String value : {0:N2}%

Applied to integer datatype only.


4. To round the numbers to one decimal place and are zero padded for numbers less than three digits.

Data Format String value : {0:000.0}

Applied to numeric and decimal datatype only.


5. Long Date format

Data Format String value : {0:D}

Applied to date and datetime datatype only.

( the above formatting is as set in the web config)


6. Short Date format

Data Format String value : {0:d}

Applied to date and datetime datatype only.

( the above formatting is as set in the web config)



6. Numeric Date format

Data Format String value : {0:yy-MM-dd}

Applied to date and datetime datatype only.



Responses

Author: Holly Chamberlain    09 Jun 2004Member Level: Bronze   Points : 0
Hi - looks great, but could you please post an example of a complete tag for a column with the formating included?
Thanks!


Author: Sathy Ouan.    31 Aug 2004Member Level: Bronze   Points : 0
Aloha Dotnet,
Thank you for the helpful information.
Keep up the great site.
Thanks,
Sathy Ouanesisouk


Author: Lilla Botlik    12 Sep 2004Member Level: Bronze   Points : 0
I have used this tag in some of my customized datagrid columns.
The tag is called DataFormatString.




Author: Mark Cutter    14 Oct 2004Member Level: Bronze   Points : 0
The doc for BoundColumn.DataFormatString Property lists 7 Format characters and also refers to Formatting Overview which refers to Standard Numeric Format Strings, which describes the Percent format P. When I try to apply DataFormatString="{0:P00}%" to a bound column that has a value 0.2, however, I do not get 20.0000%. Instead I get the default generic format 0.20% Looks like it only accepts the 7 format characters in the original doc, in spite of references to the standard formatting strings. This is probably a bug. Any idea for how to get it to work?


Author: ravi    16 Nov 2005Member Level: Bronze   Points : 0
hi kindly help me to set the date format of hhh:mm in the data grid , And one more doubt this data formating expressions will get reflected while populating the data in the grid or while entering itself it will have the effect.


Author: Senthil vel    11 Jun 2008Member Level: Gold   Points : 1
hi,
its nice..For a long period i was searching the solution for date format. finally i found it...{0:d}
thanks ...
Keep it up...


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
(No tags found.)

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: How to set Datagrid Column width
Previous Resource: Preventing a browser from caching
Return to Discussion Resource Index
Post New Resource
Category: ASP.NET/Web Applications


Post resources and earn money!
 
More Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use