代码之家  ›  专栏  ›  技术社区  ›  rob waminal

在ListView中设置bind语句中日期的格式

  •  9
  • rob waminal  · 技术社区  · 15 年前

    有没有一种方法可以格式化在ListView中绑定的日期?

    我有一段ListView

    <ListView ID="lvView" runat="server">
        <ItemTemplate>
            //... some bounded data
            <asp:Label ID="lblDate" runat="server" Text='<%# Bind("RequiredDate") %>' />
            //... another bounded data
        </ItemTemplate>
    </ListView>
    

    自从 RequiredDate 是一个 DateTime 它会展示这样的东西 10/20/2010 11:08:55 AM

    我要的是将该日期格式化为如下输出 Oct. 20, 2010 . 通常,如果它是一个日期时间,我可以写这样的东西 requiredDate.ToString("MMMM dd, yyyy") 但在ListView绑定的数据中,我不能这样做。

    我不想使用OnItemDataBound。我只想把它格式化为内联的。这有可能吗?

    3 回复  |  直到 13 年前
        1
  •  24
  •   Eonasdan    13 年前

    应该是…

    Text='<%# Bind("RequiredDate", "{0:MMM dd, yyyy}") %>'
    
        2
  •  4
  •   Ashaar    13 年前

    这应该管用

    Text='<%# Bind("DateOfBirth", "{0:MMM dd, yyyy}") %>'
    
        3
  •  0
  •   Yoosaf Abdulla    13 年前
    推荐文章