This is a migrated thread and some comments may be shown as answers.

Change Date Format String dynamically

3 Answers 297 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Technology
Top achievements
Rank 1
Technology asked on 08 Nov 2010, 03:03 PM
Dear Telerik Team,

can you please tell me how to change my column "Date" format string dynamically?

Now the column "Date" shows the date like this: "25/11/2009 12:00:00" and i want to change it (from vb.code) "25/11/2009".
The datatable is bound dynamic.

Thank you in advance for your time.

I use:
V.S. 2008 ASP (VB)
Telerik ASP.NET AJAX 2010.2.929.35 Trial

The code is:
            grdData.DataSource = GetData()
            grdData.DataBind()

            Dim colDates As GridDateTimeColumn
            colDates = grdData.Columns.FindByUniqueName("Date")
            colDates.DataFormatString = "0:MM/dd/yy"

and i get the error:

Cannot find column with UniqueName 'Date'

"Date" column exists in Grid.

Best regards,
Navarino Technology Department.


3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 08 Nov 2010, 03:44 PM
Hello Technology,

Can you verify if your scenario works normally with standard MS GridView control and let us know about the result?

All the best,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Technology
Top achievements
Rank 1
answered on 09 Nov 2010, 09:50 AM
Dear Pavlina,

first of all, thank you for your quick respond.

I didn't find any info's about dynamic change date format string for MS GridView.
All examples are from Designer, not from VB code.

So i change the date format from my SQL Store Procedure, before Grid Bound. Now i get the date format that i want.
But the question still exists for a future reference. How can i change format string dynamically for a date column?

Thank you for your time.

Best regards,
Navarino Technology Department.
0
Pavlina
Telerik team
answered on 10 Nov 2010, 10:57 AM
Hello,

To change the settings for declarative columns at runtime, write a handler for the PreRender event of the grid, traverse the Columns collection to locate the column of interest, and alter its properties. You must then rebind the grid by calling its Rebind() method to reflect the changes. More information is available in this help topic.

Kind regards,
Pavlina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Technology
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Technology
Top achievements
Rank 1
Share this question
or