Anita Level: Big Cheese Registered: 19-05-2005 Posts: 24
DataGrid formatting expression
I'm trying to display a date in my datagrid column to look like 2/22/2006. (without the time)
In the data grid property builder for the column, there is a formatting expression, but I've tried putting mm/dd/yyyy in there and that's what displays at run time and not the date.
Does anyone know what the formatting expression should look like?
Or can I do this in code?
Thank you anyone for your help.
22-02-2006 at 06:53 PM
|
~Bean~ Level: VB Guru Registered: 07-04-2003 Posts: 488
Re: DataGrid formatting expression
You may want to look at "DateTimeFormatInfo Class" in your help. I am not so familiar with the "data grid property builder", so I can't help with that (I do all my data binding in code). In fact, I may need to post a second topic on how to find it because I couldn't!
Here's how I set the Column Styles for a datagrid in code...
'Get a Dataset
'...assumes a Column called "dateStamp" and a DataTable called "tblResults"
'Build a Style
Dim dgts As DataGridTableStyle = New DataGridTableStyle
dgts.MappingName = "tblResults"
Dim dgcs As DataGridTextBoxColumn = New DataGridTextBoxColumn
dgcs.MappingName = "dateStamp"
dgcs.Width = 100
dgcs.Format = "yyyy"
dgts.GridColumnStyles.Add(dgcs)
dgGRID.TableStyles.Add(dgts)
'Bind it...
dgGRID.DataSource = List.Tables("tblResults")
There are also ways to do this on the Database side...
(SQL Server)
SELECT CONVERT(CHAR(10), dateStamp, 101) As MyDating FROM tblDates
[Edited by ~Bean~ on 27-02-2006 at 01:03 PM GMT]
____________________________
Eggheads unite! You have nothing to lose but your yolks.
27-02-2006 at 06:01 PM
|
Anita Level: Big Cheese Registered: 19-05-2005 Posts: 24
Re: DataGrid formatting expression
I'm trying to do this, but there is no DataGridTableStyle object available. I'm doing a web form. Does this code apply to web forms or windows forms?
Thanks,
27-02-2006 at 08:25 PM
|
~Bean~ Level: VB Guru Registered: 07-04-2003 Posts: 488
Re: DataGrid formatting expression
I suspected as much when I read your other topic you said a "web" control. This is for Windows forms only.
No, this property is not past of ASP.NET. In fact, it's much easier in ASP.NET. You need to make a Template Column...I will post the code later right now I have to go catch my bus...
____________________________
Eggheads unite! You have nothing to lose but your yolks.
27-02-2006 at 09:22 PM
|
Anita Level: Big Cheese Registered: 19-05-2005 Posts: 24
Re: DataGrid formatting expression
I've just now found the formatting expressions and how to enter them in the property builder. Here is what it looks like:
To display the date as 2/27/06, enter the following as the formatting expression:
{0:MM/dd/yy}
Quite simple, really. I guess this can be done in code as well.
Thanks for your help. I have to catch a bus now, too.