It depends on the way you are using your datagrid.
If you have bound columns:
On the property builder, select the bound column and add '{0:MM/dd/yyyy}' on the data formating expression.
If you have templated columns with a control to write the date on (using databindings):
On the databinding of the control add 'DataBinder.Eval(Container, "DataItem.MyDate", "{0: MM/dd/yyyy}"'
Thanks NetAngel. That did fix my formatting problem with bound columns.
If I can pick your brain a little more, how can I display negative numbers with paranthesis instead of the negative sign infront?
Also how can I get at a specific cell to input the date the correct way? I'm having issues trying to fomat the date. The format is YYYYMMDD and I want to change it to MM/DD/YYYY. Any good suggestions as to how to do this?
To format negative numbers using paranthesis use the following format:
{0:$#,###.##;($#,###.##)}
To format the data of a column on the 'MM/DD/YYYY' format, use:
{0: MM/dd/yyyy}
I'm assuming u are returning a date type field form the database.
NetAngel
The problem I'm having with the date column is I'm importing a date that's in the format: YYYYMMDD I tried using {0: MM/dd/yyyy} but the grid did not display and got the message: 'Format specifier was invalid.'
Is there a way in code to input data into certain columns? If so then I could format the dates myself.
You can use this trick to format a data column yourself.
In the html part of your page where the column is databound use this syntax[color]
<%# FormatDate(DataBinder.Eval Container, "DataSource.DataMember") %>[/color]
The bold text is the name of a function you need to code in the code-behind page. Something like so..
Protected Function FormatDate(ByVal arg As Object) As String
Dim output As String
If arg Is Nothing Then
output = 'default output for blanks
ElseIf IsDBNull(arg) Then
output = 'same as above
Else
output = 'format arg here
End If
Return output
End FunctionThat'l do donkey, that'l do
Mark
If you are unsure of forum etiquette check here faq796-2540
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.