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

Problem with Date FormatString

4 Answers 183 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jen
Top achievements
Rank 1
Jen asked on 03 Feb 2009, 12:29 PM
Below is the code of my grid:

<telerik:RadGrid ID="rgAnalysisResults"  
                 runat="server"  
                 AutoGenerateColumns="False"  
                 AllowPaging="True" 
                 AllowSorting="True" 
                 ShowStatusBar="True"  
                 Skin="BDB" EnableEmbeddedSkins="False" GridLines="None" > 
    <PagerStyle Mode="NextPrevAndNumeric"></PagerStyle> 
    <CommandItemStyle /> 
    <MasterTableView> 
 
<RowIndicatorColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</RowIndicatorColumn> 
 
<ExpandCollapseColumn> 
<HeaderStyle Width="20px"></HeaderStyle> 
</ExpandCollapseColumn> 
        <Columns> 
            <telerik:GridBoundColumn DataField="DocumentDate" HeaderText="DocumentDate"  
                UniqueName="DocumentDate" DataFormatString="{0:dd/MM/yyyy}" 
                DataType="System.DateTime" /> 
            <telerik:GridBoundColumn DataField="Parcel" HeaderText="Parcel" UniqueName="Parcel" /> 
            <telerik:GridBoundColumn DataField="LaboNbr" HeaderText="LaboNbr" UniqueName="LaboNbr" /> 
          <%--  <telerik:GridButtonColumn ButtonType="ImageButton" CommandArgument="FileName" ImageUrl="~/images/pdf.gif" 
                DataTextField="" CommandName="ShowPDF" UniqueName="FileName" HeaderText="" />--%> 
             
              <telerik:Gridtemplatecolumn UniqueName="PDF" HeaderText="Pdf"
                <ItemTemplate> 
                    <asp:ImageButton ID="DownloadPDFButton" CommandName="Download" runat="server" CommandArgument="FileName" ImageUrl="~/images/pdf.gif" /> 
                </ItemTemplate> 
                </telerik:Gridtemplatecolumn> 
               <%-- <telerik:Gridtemplatecolumn> 
                <ItemTemplate> 
                    <asp:ImageButton ID="DownloadXMLButton" CommandName="DownloadXML" runat="server" CommandArgument="FileNameXML" ImageUrl="~/images/xml.gif" /> 
                </ItemTemplate> 
                </telerik:Gridtemplatecolumn>--%> 
</Columns> 
        <NoRecordsTemplate> 
            <asp:Label ID="lblNoRecords" runat="server" Text="" ForeColor="Red" resourcekey="lblNoRecords" /> 
        </NoRecordsTemplate> 
 
<EditFormSettings> 
<EditColumn InsertImageUrl="Update.gif" UpdateImageUrl="Update.gif" EditImageUrl="Edit.gif" CancelImageUrl="Cancel.gif"></EditColumn> 
</EditFormSettings> 
        </MasterTableView> 
 
<FilterMenu Skin="BDB" EnableEmbeddedSkins="False" EnableTheming="True"
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
</FilterMenu> 
</telerik:RadGrid> 

I have a column called DocumentDate which contains dates. I am trying  to only show the date (no time), but 0:00:00 is added to all the dates. What am I doing wrong?

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 04 Feb 2009, 06:40 AM
Hi Jennifer,

I tried applying the DataFormatString as shown above and it is showing only the Date part for me. Can you try removing the DataType property for the column and see whether the DataFormatString is getting applied correctly?
 
  Also try using a GridDateTimeColumn for displaying the DateField with DataFormatString applied.

ASPX:
 <telerik:GridDateTimeColumn HeaderText="DocumentDate"   DataField="DocumentDate"  UniqueName="DocumentDate"  DataFormatString="{0:dd/MM/yyyy}"   ></telerik:GridDateTimeColumn> 


Regards
Shinu
0
Jen
Top achievements
Rank 1
answered on 04 Feb 2009, 08:11 AM
I applied your aspx code, but I still get date and time. I have no idea how to solve this :(
0
Accepted
Daniel
Telerik team
answered on 06 Feb 2009, 08:55 AM
Hello Jennifer,

A possible reason for this behavior would be if DocumentDate is not of type DateTime. Please test the example below:

incorrect (default type is string):
protected void Page_Load(object sender, EventArgs e) 
    DataTable table = new DataTable(); 
    table.Columns.Add("DocumentDate"); 
    table.Rows.Add(DateTime.Today); 
    RadGrid1.DataSource = table; 

correct:
protected void Page_Load(object sender, EventArgs e) 
    DataTable table = new DataTable(); 
    table.Columns.Add("DocumentDate"typeof(DateTime)); 
    table.Rows.Add(DateTime.Today); 
    RadGrid1.DataSource = table; 

aspx
<telerik:GridDateTimeColumn  
   HeaderText="DocumentDate" 
   DataField="DocumentDate"   
   UniqueName="DocumentDate"   
   DataFormatString="{0:dd, MM}"
</telerik:GridDateTimeColumn>  

Let us know whether this helps.

Kind regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Jen
Top achievements
Rank 1
answered on 12 Feb 2009, 01:28 PM
That helped, thank you! The format of DocumentDate was of type DateTime instead of type Date.
Tags
Grid
Asked by
Jen
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Jen
Top achievements
Rank 1
Daniel
Telerik team
Share this question
or