We help IT Professionals succeed at work.
Get Started

DataFormatString in Gridview

dparkes
dparkes asked
on
1,857 Views
Last Modified: 2008-09-16
I've looked at numerous articles on this topic but have not found a solution that helps in this particular case.

Here is my TemplateField:

                            <asp:TemplateField HeaderText="OrderDateTime" SortExpression="OrderDateTime"  >
                                <ItemTemplate>
                                    <asp:Label ID="Label1" runat="server"
                                        Text='<%# Bind("OrderDateTime", "{0:MM/dd/yyyy}") %>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <asp:Label ID="Label1" runat="server"
                                        Text='<%# Eval("OrderDateTime", "{0:MM/dd/yyyy}") %>'></asp:Label>
                                </EditItemTemplate>
                                <ItemStyle HorizontalAlign="Left" />
                            </asp:TemplateField>



DataFormatString seems to have no effect whatsoever on the appearance of the time string in the Gridview.  I have tried converting the field to an ItemTemplate and tried using HTMLENCODE="false" to no avail.

Does it have something to do with the initial string?  The string being converted is stored as a String in the database, not as a DateTime field.  And a sample of the string is like this: "8/17/2007 17:50:25.9700000".  Is this why DataFormatString doesn't work?   If so should I create a function in Code Behind to do the job?


Comment
Watch Question
CERTIFIED EXPERT
Commented:
This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE