This article shows how to format a GridView. What is GridView? The GridView is an extremely flexible grid control for showing data in a basic grid consisting of rows and columns. It has selection, paging and editing feature, and it is extensible through templates. The great advantage of Gridview over Datagrid is its support for code free scenarios. In GridView you can do many things without writing any code like paging and selection.

Formatting Fields:

To format the grid view you have to ensure that dates, currency and other number values are in good format. Grid View has property "DataFormatString" to apply formatting. You can change colors, fonts, borders and alignment of grid. Each BoundField column provides a DataFormatString property that you can use to configure the numbers and dates using a format string.

Format strings are generally made up of a placeholder and format indicator, which are wrapped inside curly brackets, like this:

{0:C}

Here 0 shows the value that will be formatted and the letter indicates a predetermined format style. In this case C means currency format which formats a number as a dollar.

Raj Kumar Beniwal is two time Microsoft MVP(Client App Dev) and four time C# Corner MVP, working as project manager with lots of hands on experience using ASP.NET 2.0/3.5, AJAX, MVC, C#, Visual Basic .NET, SQL Serv... Read more