Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i put a date from calander into gridview
it will show with time also
i just only want to show only date in gridview
Posted

In GridView you can assign a format to every column...Set the proper format to your date column and it will be displayed as wanted...
ASP.NET
<asp:boundfield datafield="Your_Date_Column" dataformatstring="{0:dd/MM/yyyy}" />
 
Share this answer
 
v2
Comments
Praveen Kumar Upadhyay 15-Dec-14 3:01am    
I guess this is nice solution. But this can give error at runtime if there is any issue in the date object. In code behind we can handle the error using try catch.
Kornfeld Eliyahu Peter 15-Dec-14 3:04am    
As long as your data is date there is no problem here. If it is not than the problem is not here either, but or in the application data or in the application logic...
Unfortunately in C# we do not have a type called Date. What we can do is we can convert the datetime to string and can display only date in string format.

C#
dateTime.ToString("yyyy-MM-dd") 
 
Share this answer
 
v2
try this
C#
Date.ToString("yyyy-MM-dd");
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900