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

Dateformat - autogenerated columns

4 Answers 224 Views
Grid
This is a migrated thread and some comments may be shown as answers.
wnl
Top achievements
Rank 1
wnl asked on 10 Nov 2009, 09:13 AM
Hi,
I'm using RadGrid with autogenerated columns. In some column I have DateTime value ( e.g. sql - select id, startDate, price from table) . How can I set the dateformat of this columns in grid which have these values?

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 10 Nov 2009, 10:06 AM
Hi Jaromin,

I tried setting the DateFormatString from code in ColumnCreated event and it is working fine for me. Give a try with this approach.


CS:
 
    protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e) 
    { 
        if (e.Column is GridBoundColumn && e.Column.UniqueName == "StartDate"
        { 
            GridBoundColumn column = (GridBoundColumn)e.Column; 
            column.DataFormatString = "{0:d}"
        } 
    } 

Regards,
Shinu.

0
wnl
Top achievements
Rank 1
answered on 10 Nov 2009, 11:32 AM
Ok, but is that any way to make this without specifying"Column.UniqueName"?
0
Accepted
Amit
Top achievements
Rank 1
answered on 19 Mar 2012, 08:27 AM
Try This.... You will get what you need
If
e.Column.DataTypeName = "System.DateTime" Then
            Dim column As GridBoundColumn = DirectCast(e.Column, GridBoundColumn)
            column.DataFormatString = "{0:m}"
End If
0
Amit
Top achievements
Rank 1
answered on 19 Mar 2012, 08:28 AM
Try This.... You will get what you need

If
e.Column.DataTypeName = "System.DateTime" Then
            Dim column As GridBoundColumn = DirectCast(e.Column, GridBoundColumn)
            column.DataFormatString = "{0:m}"
End If

Tags
Grid
Asked by
wnl
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
wnl
Top achievements
Rank 1
Amit
Top achievements
Rank 1
Share this question
or