<%
DateTime date;
var culture = new System.Globalization.CultureInfo("pt-BR");
DateTime.TryParseExact(Eval("pubDate").ToString(), "dd MMM", culture, System.Globalization.DateTimeStyles.AssumeLocal, out date);
var b = date.ToString();
%>
我试图在asp:ListView中使用wordpress feed来评估日期。我想要的是回归&#39; b 到ItemTemplate,但我不断收到此错误:
{&#34;数据关联的方法,如Eval(),XPath()和Bind()只能在控件数据绑定的上下文中使用。&#34;}
答案 0 :(得分:3)
<%# ToDate(Eval("pubDate")) %>
on.aspx.cs
protected string ToDate(object wordpressDate)
{
DateTime date;
var culture = new System.Globalization.CultureInfo("pt-BR");
DateTime.TryParse(wordpressDate.ToString(), culture, System.Globalization.DateTimeStyles.AssumeLocal, out date);
return date.ToString("dd MMM");
}