SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
<asp:TemplateField  HeaderText="Date" >                      
        <asp:Label ID="lblDat1" runat="server" Text='<%# Eval("Date", "{0:D}")%>' ></asp:Label>   

I am trying to get "Date" Colum from my List there it Displays DateTime.Now Like This

SPWeb web = SPContext.Current.Web;
SPList list = web.Lists.TryGetList(DropDownListCategory.SelectedItem.Value);

SPListItem item = list.Items.Add();
DateTime dt = DateTime.Now; // date set

item["Title"] = TextBoxTitle.Text;
item["Contents"] = TextBoxContents.Text;
item["Categories"] = DropDownListCategory.SelectedItem.Value;

item["Date"] = dt; // date used
item["Authors"] = TextBoxAuthor.Text;
item["Links"] = TextBoxLinks.Text;

I am trying to display that DateTime from the Colum "Date" in my GrindView, are the first code right, or any suggestions?

share|improve this question

Do you mind explaining what actually happens? Nothing appears or? If you Eval("Date") without the formatting, does it work? Anyways, you might want to convert to DateTime before formatting:

<asp:Label ID="lblDat1" runat="server" Text='<%# Convert.ToDateTime(Eval("Date")).ToString("D") %>' ></asp:Label>   
share|improve this answer
If you have questions, instead of posting them as answers; you can comment on the Question for clarification! – Arsalan Adam Khatri Jan 30 '13 at 19:31
@F.Aquino i get this String was not recognized as a valid DateTime. – Batistuta Jan 30 '13 at 22:41
@ArsalanAdamKhatri do u maybe now how to solve my problem? – Batistuta Jan 30 '13 at 22:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.