C# 如何在asp.net中更改DataBinder.Eval的日期格式?
我想知道如何更改日期时间格式,以便只显示日期C# 如何在asp.net中更改DataBinder.Eval的日期格式?,c#,asp.net,sql-server,C#,Asp.net,Sql Server,我想知道如何更改日期时间格式,以便只显示日期 <asp:Repeater ID="RepeaterActions" runat="server"> <ItemTemplate> <li> <span class="historyDate"><%#DataBinder.Eval(Container.DataItem, "Act
<asp:Repeater ID="RepeaterActions" runat="server">
<ItemTemplate>
<li>
<span class="historyDate"><%#DataBinder.Eval(Container.DataItem, "ActionListDate")%></span>
<span class="historyName"><%#DataBinder.Eval(Container.DataItem, "LeadActionName")%></span><br />
<span class="historyNotes"><%#DataBinder.Eval(Container.DataItem, "ActionListNote")%></span>
</li>
</ItemTemplate>
</asp:Repeater>
<pre>
protected void RepeaterActionsFill()
{
string sql = @" select a.ActionListDate, a.LeadListID,
a.ActionListNote,
l.LeadActionName
from ActionLists as a
INNER JOIN LeadActions as l
ON a.LeadActionID = l.LeadActionID
where a.LeadListID = " + Convert.ToInt32(Request["id"].ToString());
RepeaterActions.DataSource = DBUtil.FillDataReader(sql);
RepeaterActions.DataBind();
}
</pre>
我猜是介于两者之间,但我不确定
我的代码是:
受保护的void RepeaterActionsFill()
{
字符串sql=@“选择a.ActionListDate、a.LeadListID、,
a、 ActionListNote,
l、 LeadActionName
从行动列表中作为
内部连接引线动作为l
在a.LeadActionID=l.LeadActionID上
其中a.LeadListID=“+Convert.ToInt32(请求[“id”].ToString());
RepeaterActions.DataSource=DBUtil.FillDataReader(sql);
RepeaterActions.DataBind();
}
目前,它看起来是这样的:
我要找的是时间戳在那里
感谢您的帮助
编辑:
以下是我一直在寻找的:
<%#DataBinder.Eval(Container.DataItem, "ActionListDate").ToString("dd/MM/yyyy") %>
现在无法测试此代码,但是否有类似的内容
<%# DataBinder.Eval(Container.DataItem, "ActionListDate", "{0:d/M/yyyy hh:mm:ss tt}") %>
给出格式,例如:
string sql = string.Format(@"select a.ActionListDate, a.LeadListID,
a.ActionListNote,
l.LeadActionName
from ActionLists as a
INNER JOIN LeadActions as l
ON a.LeadActionID = l.LeadActionID
where a.LeadListID = {0};", Request["id"]);
您也可以将tsql更改为以下内容,或者只需删除Convert.ToInt32()
我把这个放在代码后面:
并在XHTML中使用:
Text='
'
您可以为任何类型修改此选项 太完美了!你怎么能记下8年前的东西!显然,方法已经改变了,傻瓜
string sql = string.Format(@"select a.ActionListDate, a.LeadListID,
a.ActionListNote,
l.LeadActionName
from ActionLists as a
INNER JOIN LeadActions as l
ON a.LeadActionID = l.LeadActionID
where a.LeadListID = {0};", Request["id"]);
public string makeShortDate(object oDate)
{
if (oDate is DBNull) {
return "";
} else {
DateTime dDate = Convert.ToDateTime(oDate);
string sDate = dDate.ToShortDateString();
return sDate;
}
}