Formatting the date display

Formatting the date display

In order to format the date display in an ASP.NET web page, you can use the DataFormatString property of the BoundField or TemplateField in the GridView control.

Here’s an example of how to use it:

<asp:GridView ID=”GridView1″ runat=”server” AutoGenerateColumns=”False” DataSourceID=”SqlDataSource1″>

    <Columns>

        <asp:BoundField DataField=”Date” HeaderText=”Date” DataFormatString=”{0:d}” />

        <asp:BoundField DataField=”Description” HeaderText=”Description” />

        <asp:BoundField DataField=”Amount” HeaderText=”Amount” DataFormatString=”{0:C}” />

    </Columns>

</asp:GridView>

In this example, the DataFormatString property is set to {0:d} for the “Date” column and {0:C} for the “Amount” column. The d format specifier is used to display the date in a short date format, while the C format specifier is used to display the amount in a currency format.

You can use other format specifiers as well, such as g for a short date and time format, t for a short time format, and yyyy-MM-dd for a custom date format. Note that the format specifier is enclosed in braces {} and includes a placeholder {0} for the value to be formatted. The value will be replaced with the actual value from the data source.

Apply for ASP.NET Certification Now!!

https://www.vskills.in/certification/certified-aspnet-programmer

Back to Tutorial

Share this post
[social_warfare]
Formatting Document
Bitwise Operators in PHP

Get industry recognized certification – Contact us

keyboard_arrow_up