Click here to Skip to main content
15,886,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi frnds,
In my application,i m using a gridview which fetches value from racle database,there is a linkbutton where when the user clicks on it..a pop up msg pops up...now...in the gridview there is a coumn called start date of type datetime..in the pop up msg the user can edit this start date..i m getting the start date value from the grid view using query strings...now..i just wanna display the date and not the time in the pop up msg.
textbox.text=strings[3];

is the statement i m using,where string[3] is the value containing...11/2/2012 12:00 am.
Now,
i want textbox.text to have oly 11/2/2012.
how do i do??
pls help
thanks
Posted
Updated 12-Jan-12 19:03pm
v2

C#
<asp id="Label1"  runat="server" Label.Text='<%# Eval("date", "{0:M-dd-yyyy}") %>'>
 
Share this answer
 
v3
Comments
Member 8459400 13-Jan-12 0:11am    
thanks for replying..from the database i m getting data as 12/2/2011...now i have to show only 12/2/2011 in the gridview..how do i show?
member60 13-Jan-12 0:59am    
while binding the date fields from database try to foramt it as:
Eval("date", "{0:dd/MM/yyyy}")
where "date" is the database column you want to bind
or see my improved solution:
Member 8459400 13-Jan-12 5:16am    
thank u so much :) it worked...
Omkar Hendre 1-Aug-14 2:08am    
thank you it works for me thank you very much sir
Try DateTime dateOnly = date.Date;
 
Share this answer
 
try this way
in template of grid
XML
<asp:Label id="Label1" runat="server" Text='<%# Eval("CreationDate", "{0:M-dd-yyyy}") %>'>
    </asp:Label>



or refer this link for more details
http://peterkellner.net/2006/05/24/how-to-set-a-date-format-in-gridview-using-aspnet-20using-htmlencode-property/[^]
 
Share this answer
 
You should use DataFormatString Parameter in Grid View

ASP.NET
<asp:BoundField DataField="DateColumn" DataFormatString="{0:dd/mm/yyyy}" />


and you can assign this value directly to textbox
 
Share this answer
 
v2
Comments
Technoses 13-Jan-12 0:58am    
If solve please rate this as your solution
You can set the datetime format in Gridview in following way,

XML
<asp:BoundField DataField="HDate" DataFormatString="{0:dd'/'MM'/'yyyy}" HeaderText="Date"
HtmlEncode="False" SortExpression="HDate">
</asp:BoundField>
 
Share this answer
 
Comments
tianyacao8025 13-Jan-12 2:14am    
using format as {0:dd'/'MM'/'yyyy} is ok
 
Share this answer
 
using format as {0:dd'/'MM'/'yyyy} is ok
 
Share this answer
 
use below
<asp id="Label1" runat="server" label.text="<%# Convert.Todate(Eval("date")).toShortDateString() %>"></asp>
 
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