Reputation: 55
I've got a GridView that displays dates as "dd-mm-yyyy" which is what I want, but when editing I get "dd-mm-yyyy 00:00:00". Since I am using a date data type, I don't want the time included when editing since my validation for date will only accept "dd/mm/yyyy". Am I using the wrong data type or do I need to change this line?
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("GameDate") %>'></asp:TextBox>
This GridView is taking data from a database.
Upvotes: 1
Views: 568
Reputation: 4591
I assume the GridView field is a template Field? If so give this a try:
<asp:TemplateField HeaderText="Game Date" SortExpression="GameDate">
<EditItemTemplate>
<asp:TextBox ID="TextBox5" runat="server" Text='<%# Bind("GameDate","{0:MM-dd-yyyy}") %>' ID="TextBox1"></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%# Bind("GameDate", "{0:MM-dd-yyyy}") %>' ID="Label1"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
Upvotes: 1
Reputation: 3410
Use formatting
<%# (DateTime.Parse(Eval("GameDate").ToString()).ToString("MM/dd/yyyy")) %>
Upvotes: 1
Reputation: 8545
Convert(varchar(30),GameDate,103) as GameDate
Use convert function in database select query. It will remove time.
Upvotes: 0