1

我有一个 detailsView,其单元格中的日期值当前以 longDateFormat 显示,我想将此 DetailsView 中的所有日期值转换为短日期。

例如,而不是6/1/2010 12:00:00 AM,我只想显示6/1/2010

对于 Gridview,我可以通过代码来实现

  Protected Sub DetailsView4_DataBound(ByVal sender As Object, ByVal e As System.EventArgs) Handles DetailsView4.DataBound

    If e.Row.RowType = DataControlRowType.DataRow Then
        For i As Integer = 0 To e.Row.Cells.Count - 1
            Dim cellDate As Date
            If Date.TryParse(e.Row.Cells(i).Text, cellDate) Then
                e.Row.Cells(i).Text = String.Format("{0:d}", cellDate)
            End If
        Next
    End If

End Sub

如何使用 DetailsView 实现相同的效果?

4

1 回答 1

2

它可以简单地实现,如果它在模板文件中..

<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("tDate", "{0:MM/dd/yyyy}") %>'></asp:TextBox>

或者如果它不是模板字段,那么

<asp:BoundField DataField="tDate" HeaderText="tDate" SortExpression="tDate" DataFormatString="{0:MM/dd/yyyy}" HtmlEncode="False" />
于 2010-09-07T14:28:44.033 回答