Showing posts with label zero padding in gridview. Show all posts
Showing posts with label zero padding in gridview. Show all posts

Thursday, June 4, 2009

DataFormatString to put leading zeros in ASP.NET GridView BoundField Column

If we want to display values like 0001, 0002 rather than 1,2 in the gridview columns, we need to make use of DataFormatString property of asp:BoundField in gridview.

So to put leading zeros or to zero pad the values displayed using bound field in gridview use this...

DataFormatString="{0:0000}"

To show the date in dd/MM/yyyy format, use this...

DataFormatString="{0:dd/MM/yyyy}"

This will be useful when we need to show only the date part and skip the time part.

:)