Click here to Skip to main content
15,909,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In grid view I am using dataformatstring{0:dd-MM-yyy}
but it is not working on all forms where i have used it. it is showing correct result on 2-3 pages out 10
Posted
Comments
Prerak Patel 19-Sep-11 4:09am    
You are missing a 'y'. Is it a typo? Try {0:dd-MM-yyyy}
Qureshali 19-Sep-11 4:14am    
Sorry I have missed a 'y' in question but in my code its dataformatstring{0:dd-MM-yyyy}. But it is not working. Is there any other way of retrieving only date part in dd-mm-yyyy format. Please help me

while binding the grid
use
<%# Eval("startTime", "{0:dd MMM yyyy}")%>
 
Share this answer
 
Comments
Anuja Pawar Indore 19-Sep-11 4:24am    
<%#Convert.ToDateTime(Eval("StartDate")).ToString("dd MMM yyyy")%>
Member 11054586 4-Dec-14 0:55am    
thnkz :)
Anuja Pawar Indore 5-Dec-14 4:09am    
Welcome :)
 
Share this answer
 
Hi,

Use string.split in databinding method in c#

like
C#
res.dt.rows[0][4].tostring().split(" ");


We know already to date format in database is 12-34-1999 12:00:11PM

thn we break that data and time we use date as per our requirement .

And another method is using eval() function in grid view

as I said in earlier.

]]>

I hop you understand what i said.
 
Share this answer
 
use this in query where you are getting date field

CONVERT(VARCHAR,date column name,103) as date


sorry if i misunderstand your question

ex:

select column1,column2,CONVERT(VARCHAR,date column name,103) as date from tablename
 
Share this answer
 
v2
{0:dd-MM-yyyy}

 You Missed Y in this line 
 
Share this answer
 
SQL
set the dataformatstring value to "{0:d}"

Ex:


XML
<asp:BoundField HeaderText="Date" DataField="Date_Field" ReadOnly="True" DataFormatString="{0:d}">
</asp:BoundField>
 
Share this answer
 
C#


XML
<asp:TemplateField HeaderText="DOB">
                                           <ItemTemplate>
                                             <%#Eval("DOB", "{0:dd-MM-yyyy}") %>
                                           </ItemTemplate>
                                       </asp:TemplateField>
 
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