【问题标题】:ASP.NET date format in DetailsViewDetailsView 中的 ASP.NET 日期格式
【发布时间】:2013-06-18 18:35:51
【问题描述】:

这个错误把我吓坏了。事实证明,DetailsView 中的日期格式是错误的。这似乎是一个非常明显的错误,因为您只需要应用 DataFormatString 但正如您所见,我已经这样做了。我尝试了 {0:d} 和 {0:dd/MM/yyyy} 格式,并尝试将 BoundFields 替换为 TemplateField,其中我使用 Bind 函数并将格式字符串作为第二个参数。它显示正确的日期,但格式为 dd/MM/yyyy hh:mm:ss。

<asp:DetailsView DataSourceID="SqlDataSource1" runat="server" DefaultMode="Edit" AutoGenerateRows="false" ID="EditView" DataKeyNames="id" CssClass="editing-padding" AutoGenerateEditButton="true" OnModeChanging="EditView_ModeChanging" OnItemUpdating="EditView_ItemUpdating">
    <Fields>
        <asp:BoundField HeaderText="Startdato" DataField="start_time" DataFormatString="{0:dd/MM/yyyy}"/>
        <asp:BoundField HeaderText="Slutdato" DataField="end_time" DataFormatString="{0:dd/MM/yyyy}"/>
        <asp:TemplateField>
            <HeaderTemplate>
                Kommentar
            </HeaderTemplate>
            <EditItemTemplate>
                <asp:TextBox ID="commentBox" runat="server" Text='<%# Bind("comment") %>' TextMode="MultiLine" Width="300" Height="150"></asp:TextBox>
            </EditItemTemplate>
        </asp:TemplateField>
    </Fields>
    <RowStyle BackColor="White" />
</asp:DetailsView>

提前感谢您的帮助

【问题讨论】:

    标签: asp.net bind date-format detailsview


    【解决方案1】:

    默认情况下,BoundField 似乎仅在只读模式下应用DataFormatString 指定的格式。尝试将 ApplyFormatInEditMode="true" 属性应用于您的 BoundField,如下所示:

    <asp:BoundField HeaderText="Slutdato"
    DataField="end_time" 
    DataFormatString="{0:dd/MM/yyyy}" 
    ApplyFormatInEditMode="true" />
    

    希望对我有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-11-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-20
      • 2010-10-18
      相关资源
      最近更新 更多