asp.net中gridview的日期时间格式 [英] asp.net formatting dateTime in gridview
问题描述
我是动态地从一个在我的数据库我已经被称为会话表绑定一个gridview。我得到使用LINQ查询是这样的,从方法的信息:
I'm binding a gridview dynamically from a table in my database I have called "Sessions". I get the information from a method using a linq query that is something like this:
var s = from sessions in datacontext.Sessions
where sessions.test == id
orderby sessions.ID ascending
select sessions;
gridView.DataSource = qsessions;
gridView.DataBind();
会话包含我希望尽量减少只显示日期(月/日/年)时间字段。从我通过谷歌搜索看,解决的办法是使用类似GridView控件的ASPX标记来指定格式:
Sessions contains a dateTime field that I want to minimize to just display the date (month/day/year). From what I've read through google searches, the solution is to specify the formatting in the aspx markup of the gridview using something like:
<asp:TextBox ID="txtDate" runat="server" Text='<%# Eval("dateTime", "{0:MM/dd/yyyy}") %>'></asp:TextBox>
这似乎并没有工作,仍然显示日期后的时间。有我丢失的东西?帮助非常AP preciated!
It doesn't seem to work and still shows the time after the date. Is there something I'm missing? Help much appreciated!
推荐答案
尝试:
<asp:TextBox ID="txtDate" runat="server" Text='<%# Convert.ToDateTime(Eval("dateTime")).ToString("d") %>'></asp:TextBox>
有关更多的格式设置选项,请参阅本网站有帮助的:
See this helpful site for more formatting options:
<一个href=\"http://www.mikesdotnetting.com/Article.aspx?ArticleID=23\">http://www.mikesdotnetting.com/Article.aspx?ArticleID=23
这篇关于asp.net中gridview的日期时间格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!