Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.
<asp:TemplateField  HeaderText="Date" >                      
    <ItemTemplate>
        <asp:Label ID="lblDat1" runat="server" Text='<%# Eval("Date", "{0:D}")%>' ></asp:Label>   
    </ItemTemplate>
</asp:TemplateField>

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
add comment

1 Answer 1

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. –  Martin Jan 30 '13 at 22:41
    
@ArsalanAdamKhatri do u maybe now how to solve my problem? –  Martin Jan 30 '13 at 22:42
add comment

Your Answer

 
discard

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.