This is a migrated thread and some comments may be shown as answers.
Date format not working on Grid.
3 Answers 53 Views
This is a migrated thread and some comments may be shown as answers.
Danny
Top achievements
Rank 1
Danny asked on 24 Jun 2011, 12:02 AM
I have a RadGrid that has a date column in it. I am trying to display the date in UK format, i.e. dd/MM/yyyy.  I have tried using DataFormatString="{0:dd/MM/yyyy}" in the data bound column, with no joy. If anyone could please point me in the right direction. I would much appreciate it. 



   <telerik:RadGrid ID="rgPhoneMessages" Width="100%" runat="server" GridLines="None" AllowPaging="false"
     PagerStyle-AlwaysVisible="false"  PagerStyle-Visible="false"   OnItemCommand="rgPhoneMessages_ItemCommand" 
       AllowSorting="True"    >
            <ClientSettings EnablePostBackOnRowClick="true"  Selecting-AllowRowSelect="true"  >
                <Scrolling AllowScroll="false" EnableVirtualScrollPaging="false" UseStaticHeaders="true"  SaveScrollPosition="true"></Scrolling>
            </ClientSettings>
 <MasterTableView AutoGenerateColumns="false"  DataKeyNames="ID">
    <Columns>
    <telerik:GridBoundColumn HeaderText="ID"  Visible="false"
      ItemStyle-Height="45px"  DataField="ID"  
      UniqueName= "ID" Display="True"></telerik:GridBoundColumn>
      <telerik:GridBoundColumn  DataField="Date" meta:ResourceKey="hdrDate" ItemStyle-Height="45px"
      UniqueName= "Date" Display="True" SortExpression="Date"  DataFormatString="{0:dd/MM/yyyy}" HtmlEncode="false" ></telerik:GridBoundColumn>
      <telerik:GridBoundColumn  DataField="Caller" meta:ResourceKey="hdrCaller" ItemStyle-Height="45px"
      UniqueName= "Caller" Display="True"></telerik:GridBoundColumn>
      <telerik:GridBoundColumn  DataField="Phone" meta:ResourceKey="hdrPhone" ItemStyle-Height="45px"
      UniqueName= "Phone" Display="False"></telerik:GridBoundColumn>
            <telerik:GridBoundColumn  DataField="Mode" meta:ResourceKey="hdrMode" ItemStyle-Height="45px"
      UniqueName= "Mode" Display="True"></telerik:GridBoundColumn>
    </Columns>
   </MasterTableView>    
   </telerik:RadGrid>

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 24 Jun 2011, 08:26 AM
Hello Danny,

In order to apply the proper format for the column values, double-check that the corresponding column  in the grid source is of the proper type - DateTime (for dates). Then its values should be formatted as expected. I tried the same code which worked as expected in my end.

Thanks,
Princy.
0
Danny
Top achievements
Rank 1
answered on 24 Jun 2011, 02:08 PM
Thanks for your reply.. 

The grid is binding to a data table, and the data table is using the DateTime type for the field. Although it seems to be completely disregarding this fact. 

            DataTable dt = new DataTable();


               dt.Columns.Add("ID", typeof(Int32));
               dt.Columns.Add("Date", typeof(DateTime));
               dt.Columns.Add("Caller", typeof(String));
               dt.Columns.Add("Staff", typeof(String));
               dt.Columns.Add("Phone", typeof(String));
               dt.Columns.Add("Mode", typeof(String));
               dt.Columns.Add("Case_ID", typeof(String));
               dt.Columns.Add("Message", typeof(String));
  
            SqlDataReader reader = cmd.ExecuteReader();


            while (reader.Read())
            {
                dt.Rows.Add(
                                        Convert.ToInt32(reader["ID"].ToString()),
                                       Convert.ToDateTime(reader["Date"].ToString()),
                                       reader["Caller"].ToString(),
                                       reader["Staff"].ToString(),
                                       reader["Phone"].ToString(),
                                       reader["Mode"].ToString(),
                                       reader["Case_ID"].ToString(),
                                       reader["Message"].ToString());
            }
            reader.Close();
            cmd.Connection.Close();


            return dt;


        }

0
Marin
Telerik team
answered on 28 Jun 2011, 04:45 PM
Hello Danny,

 I tried to reproduce the issue using your code sample but no avail. You can find attached the page that worked on my side.
Let me know how it works on your end. Also if the problem persists I will appreciate if you could open a formal support ticket and send us a sample application that reproduces the problem so we can investigate on our end and provide better assiatance.

All the best,
Marin
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

Tags
Grid
Asked by
Danny
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 1
Danny
Top achievements
Rank 1
Marin
Telerik team
Share this question
or