如何在gridview中绑定时格式化日期时间

发布于 2024-12-02 08:40:41 字数 470 浏览 0 评论 0原文

我有一个 DateTime 类型的字段,它绑定在 gridview 中。
现在,我想仅显示该字段中的日期,而不是时间。
日期应采用 1/1/0001 这种格式。
我正在使用 DotnetNuke

我的代码如下

<asp:TemplateField HeaderText="Created On">
    <itemtemplate>
        <%#DataBinder.Eval(Container.DataItem, "Alb_Created_Date","0:dd/MM/yyyy}")%>
    </itemtemplate>
</asp:TemplateField>`.

我已尝试使用的格式,但其输出如下 1/1/0001 12:00:00 AM

我该怎么办?

I have a field of type DateTime which is bound in gridview.
Now, i would liketo display only date from this field, and not time.
Date Should be in 1/1/0001 this format.
I am using DotnetNuke

My code is as follows

<asp:TemplateField HeaderText="Created On">
    <itemtemplate>
        <%#DataBinder.Eval(Container.DataItem, "Alb_Created_Date","0:dd/MM/yyyy}")%>
    </itemtemplate>
</asp:TemplateField>`.

I have tried the format that is used but its output is like this 1/1/0001 12:00:00 AM.

What shall I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

琉璃繁缕 2024-12-09 08:40:41

您缺少左尖括号{。试试这个。

<asp:TemplateField HeaderText="Created On">
    <itemtemplate>
        <%# DataBinder.Eval(Container.DataItem, "Alb_Created_Date", "{0:dd/MM/yyyy}")%>
    </itemtemplate>
</asp:TemplateField>

You are missing an opening angular brace {. Try this.

<asp:TemplateField HeaderText="Created On">
    <itemtemplate>
        <%# DataBinder.Eval(Container.DataItem, "Alb_Created_Date", "{0:dd/MM/yyyy}")%>
    </itemtemplate>
</asp:TemplateField>
姜生凉生 2024-12-09 08:40:41

在您的代码中,您在格式中给出了错误的语法,因此它的格式不正确并给出了数据库值本身。请按如下格式设置。

<%#DataBinder.Eval(Container.DataItem, "Alb_Created_Date","{0:dd/MM/yyyy}")%>

In your code you have given wrong syntax in the format, and due to which its not formatting correctly and giving out the data base value itself. Please, format it as below.

<%#DataBinder.Eval(Container.DataItem, "Alb_Created_Date","{0:dd/MM/yyyy}")%>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文