简体   繁体   中英

change Date format in VB.Net

How to change the Date format in a asp grid displaying date format populated from Database. The Database stores value in '2009-08-23 10:24:00.000' format but the value in grid is displayed as 'Sun 23-08-2009 10:24:00' I want to display it as '23-AUG-2008' VB .Net Code

"Dim dv As DataView1 = ds.Tables(0).DefaultView"

Markup is

<asp:BoundColumn    DataField="DateFormat"  HeaderText="Day&amp;Date">    
<ItemStyle Wrap="False" />

How can i display as '23-AUG-2008'?

You can use DataFormatString property of the BoundColumn . There just specify the desired format.

In your case:

<asp:BoundColumn DataField="DateFormat" DataFormatString="{0:dd-MMM-YYYY}" HeaderText="Day&amp;Date">    

Btw, DataGridView is a control from Winforms, not webforms...In webforms it's called GridView . And this has nothing to do with javascript or vb.net, so I've removed the tags as well.. The solution is specific to GridView control, which belongs to asp.net as whole no matter the code-behind language. Yes, you could use javascript to format those string, but...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM