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

Grouping shows time along with Date

4 Answers 150 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Aswin S
Top achievements
Rank 1
Aswin S asked on 29 Jan 2010, 06:24 AM
I have a GridTemplateColumn in a RadGrid. It was a DateTime Column.

<telerik:GridTemplateColumn FilterListOptions="VaryByDataType" DataType="System.DateTime" 
                    DataField="cr_task_dt" GroupByExpression="cr_task_dt Group By cr_task_dt" HeaderText="Next date to contact" 
                    UniqueName="cr_task_dt" SortExpression="cr_task_dt"
                    <ItemTemplate> 
                        <asp:Label runat="server" ID="lblTaskDate" Text='<%# Eval("cr_task_dt_str") %>'></asp:Label> 
                    </ItemTemplate> 
                    <EditItemTemplate> 
                        <asp:TextBox CssClass="datepicker" ID="txtTaskDate" Text='<%# Eval("cr_task_dt") %>' 
                            runat="server"></asp:TextBox> 
                        <ajax:MaskedEditExtender ID="MaskedEditExtender4645" runat="server" TargetControlID="txtTaskDate" 
                            Mask="99/99/9999" MessageValidatorTip="true" OnFocusCssClass="MaskedEditFocus" 
                            OnInvalidCssClass="MaskedEditError" MaskType="Date" DisplayMoney="Left" AcceptNegative="Left" 
                            CultureName="zh-SG" ErrorTooltipEnabled="True" /> 
                    </EditItemTemplate> 
                </telerik:GridTemplateColumn> 

The grid datasource was a linqdatasource. It works fine in all functionalities like sorting,filtering and grouping.
The only issue is it shows Time part in the grouping header as below,

"Next date to conact: 6/1/2010 12:00:00 AM"

"Next date to conact: 4/12/2010 12:00:00 AM"

I dont want the Time part (12:00:00 AM) to be displayed in the group header.  How to remove it?

Please help me sort it out. Thanks in advance.

Regards,

Aswin Suriya


4 Answers, 1 is accepted

Sort by
0
Schlurk
Top achievements
Rank 2
answered on 01 Feb 2010, 03:40 PM
I believe all you have to set is the DataFormat string as follows:

DataFormatString="{0:dd/MM/yyyy}" 

This should take of displaying only the date and not the time.
0
Aswin S
Top achievements
Rank 1
answered on 01 Feb 2010, 05:06 PM
Thanks for your reply,
But, I dont think GridTemplateColumn have a property called "DataFormatString"
0
Accepted
Princy
Top achievements
Rank 2
answered on 02 Feb 2010, 07:28 AM
Hi,

Try the code snippet below to format the group header item.

C#
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        if (e.Item is GridGroupHeaderItem) 
        { 
            GridGroupHeaderItem item = (GridGroupHeaderItem)e.Item; 
            DataRowView groupDataRow = (DataRowView)e.Item.DataItem; 
            item.DataCell.Text = ((DateTime)groupDataRow["OrderDate"]).ToShortDateString(); 
            } 
        } 
    } 

For more information on the same

Thanks,
Princy


0
Aswin S
Top achievements
Rank 1
answered on 02 Feb 2010, 01:26 PM
Bingo! Thank you very much for the snippet Princy.
That worked like a charm.
Tags
Grid
Asked by
Aswin S
Top achievements
Rank 1
Answers by
Schlurk
Top achievements
Rank 2
Aswin S
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or