I have one Repeater

 <asp:Repeater ID="repID" runat="server">
           <ItemTemplate>
                 <tr>
                       <td>
   <%# DataBinder.Eval(Container, "DataItem.DateCreated.ToShortDateString()")%>
                       </td>
                       <td>
   <%# DataBinder.Eval(Container, "DataItem.Comment")%>
                        </td>
                </tr>
           </ItemTemplate>
</asp:Repeater>

I want to show field DateCreated ToShortDateString(), but it gives me this error:

DataBinding: 'ToShortDateString()' is not a valid indexed expression.

how transform DateTime to ToShortDateString() ?

有帮助吗?

解决方案

There is an overloaded method that accepts a third parameter - a format string:

<%# DataBinder.Eval(Container, "DataItem.DateCreated", "{0:d}") %>

The format specifier "d" outputs the date using the short date pattern. You can find other specifiers on MSDN.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top