1

ASP.NetのDetailsViewは、LateTimeArrivedAtSchoolと呼ばれるテンプレートフィールドです。このフィールドのデータは、SQLServerの[時間]列からのものです。データベース内のデータは、時間、分、秒として保存されます。

時間と分のみで表示したいと思います。

テンプレートフィールドのマークアップは次のとおりです。

<asp:TemplateField HeaderText="Late Time Arrived At School:" SortExpression="LateTimeArrivedAtSchool">
    <EditItemTemplate>
        <asp:TextBox ID="TextBoxLateTimeArrivedAtSchool" runat="server" 
            Text='<%# Bind("LateTimeArrivedAtSchool") %>'></asp:TextBox>
    </EditItemTemplate>

    <InsertItemTemplate>
        <asp:TextBox ID="TextBoxLateTimeArrivedAtSchool" runat="server" 
            Text='<%# Bind("LateTimeArrivedAtSchool") %>'></asp:TextBox>
    </InsertItemTemplate>

    <ItemTemplate>
        <asp:Label ID="LabelLateTimeArrivedAtSchool" runat="server" 
            Text='<%# Bind("LateTimeArrivedAtSchool", "{0:hh:mm}") %>'></asp:Label>
    </ItemTemplate>

    <ItemStyle ForeColor="Blue" />
</asp:TemplateField>

「{0:hh:mm}」を使用すると、「入力文字列が正しい形式ではありませんでした」というエラーが生成されます。

Bindステートメントで何を使用する必要があるか教えてください。

*更新* 列のSQLServerデータ型をTime列からDateTime列に変更し、データの時間のみの部分を表示できるようにしました。

4

1 に答える 1

1

bindの代わりにevalを使用する

Text='<%# string.Format("{0:hh:mm}", Eval("LateTimeArrivedAtSchool")) %>'
于 2013-01-03T20:35:19.523 に答える