In an ASP.Net DetailsView is a templete field called LateTimeArrivedAtSchool. The data for this field is from a SQL Server Time column. The data in the database in stored as hours, minutes and seconds.
We would like to display it as only hours and minutes.
Here is the markup for the template field:
<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>
using "{0:hh:mm}" produces an error that states the "Input string was not in a correct format."
Can you tell me what we need to use in the Bind statement?
* UPDATE * I changed the SQL Server data type of the column from a Time column to a DateTime column and was able to display the time only portion of the data.
Use eval instead of bind
Text='<%# string.Format("{0:hh:mm}", Eval("LateTimeArrivedAtSchool")) %>'