Ответ 1
укажите формат, например:
<%# DataBinder.Eval(Container.DataItem, "ActionListDate", "{0:d/M/yyyy hh:mm:ss tt}") %>
Я пытаюсь понять, как изменить формат даты и времени, поэтому будет отображаться только дата.
<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>
В настоящее время он выглядит следующим образом:
И то, что я ищу, - это то, что там будет отметка времени.
Любая помощь приветствуется.
EDIT:
Вот что я искал:
<asp:Repeater ID="RepeaterActions" runat="server">
<ItemTemplate>
<li>
<span class="historyDate"><%#DataBinder.Eval(Container.DataItem, "ActionListDate", "{0:M/d/yy}")%></span>
<span class="historyName"><%#DataBinder.Eval(Container.DataItem, "LeadActionName")%></span><br />
<span class="historyNotes"><%#DataBinder.Eval(Container.DataItem, "ActionListNote")%></span>
</li>
</ItemTemplate>
</asp:Repeater>
укажите формат, например:
<%# DataBinder.Eval(Container.DataItem, "ActionListDate", "{0:d/M/yyyy hh:mm:ss tt}") %>
<%# string.Format("{0:ddd MMM yyyy}", Eval("ActionListDate"))%>
Я поместил это в код позади:
public string makeShortDate(object oDate)
{
if (oDate is DBNull) {
return "";
} else {
DateTime dDate = Convert.ToDateTime(oDate);
string sDate = dDate.ToShortDateString();
return sDate;
}
}
И используйте это в XHTML: Text = '<% # makeShortDate (DataBinder.Eval(Container.DataItem, "MyDate" ))% > ' Вы можете изменить это для любого типа.
также вы можете изменить свой tsql следующим образом или просто удалить Convert.ToInt32()
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"]);
Не удается проверить этот код прямо сейчас, но что-то вроде строк?
<%#DataBinder.Eval(Container.DataItem, "ActionListDate").ToString("dd/MM/yyyy") %>