Gridview Formating Question

kcwallace

Centurion
Joined
May 27, 2004
Messages
175
Location
Austin, TX
I am using the following to generate a field in a gridview. Is there a way to format the data? specifically this is a returned date of 1/1/2007, but it displays the 1/1/2007 12:00. I need to drop the 12:00. THe backend is SQL Server 2005. Do I need to format it there?

Code:
<asp:TemplateField  HeaderText="SD" SortExpression="StartDate">
     <ItemTemplate>
                <asp:Label ID="Label15" runat="server" Text='<%# Bind("startdate") %>'></asp:Label>
     </ItemTemplate>
     <EditItemTemplate>
                 <asp:TextBox ID="txtStartDate" runat="server" Text='<%# Bind("startdate") %>'></asp:TextBox>
      </EditItemTemplate>
      <FooterTemplate>
                  <asp:TextBox ID="txtStartDate" runat="server" Text=""></asp:TextBox>
       </FooterTemplate>
</asp:TemplateField>
 
You should be able to specify a valid format string as part of the binding expression i.e.

Code:
'<%# Bind("startdate") %>'
'replace with
'<%# Bind("startdate", "d") %>'

for a handy list of supported format codes try here
 
Back
Top