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

+

3 Answers 19 Views
Grid
This is a migrated thread and some comments may be shown as answers.
matt
Top achievements
Rank 1
matt asked on 29 Nov 2010, 03:34 PM
Hi everyone,

I have a RadGrid which i am builind up from xml in my code behind. The problem is that when sorting the 'date created' column, the grid sorts the fields as if it were a string. For example 01/03/10 would come before 02/03/05.

Here is the code:

 

<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server">

 

 

<telerik:RadGrid ID="rgHistory" ItemStyle-Font-Size="10px" AlternatingItemStyle-Font-Size="10px"

 

 

HeaderStyle-Font-Size="10px" runat="server" AllowSorting="True"

 

 

Skin="WebBlue" Width="895px" AutoGenerateColumns="false">

 

 

<AlternatingItemStyle Font-Size="10px" />

 

 

<ItemStyle Font-Size="10px" />

 

 

<MasterTableView TableLayout="Fixed" Width="100%">

 

 

<Columns>

 

 

<telerik:GridDateTimeColumn DataField="Created Date" DataType="System.DateTime" DataFormatString="{0:dd/MM/yyyy}" HeaderStyle-Width="50px" HeaderText="Created Date"

 

 

UniqueName="Created Date" >

 

 

<HeaderStyle Width="52px" />

 

 

</telerik:GridDateTimeColumn>

 

 

<telerik:GridBoundColumn DataField="Details" HeaderStyle-Width="360px" HeaderText="Details"

 

 

UniqueName="Details">

 

 

<HeaderStyle Width="360px" />

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Handler" HeaderStyle-Width="75px" HeaderText="Handler"

 

 

UniqueName="Handler">

 

 

<HeaderStyle Width="75px" />

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Action Type" HeaderStyle-Width="40px" HeaderText="Action Type"

 

 

UniqueName="Action Type">

 

 

<HeaderStyle Width="39px" />

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Corr Type" HeaderStyle-Width="40px" HeaderText="Corr Type"

 

 

UniqueName="Corr Type">

 

 

<HeaderStyle Width="39px" />

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Cost Code" HeaderStyle-Width="80px" HeaderText="Cost Code"

 

 

UniqueName="Cost Code">

 

 

<HeaderStyle Width="80px" />

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="No of Units" HeaderStyle-Width="40px" HeaderText="No of Units"

 

 

UniqueName="No of Units">

 

 

<HeaderStyle Width="39px" />

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Cost Value" HeaderStyle-Width="40px" HeaderText="Cost Value"

 

 

UniqueName="Cost Value">

 

 

<HeaderStyle Width="39px" />

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Completed Date" HeaderStyle-Width="50px" HeaderText="Completed Date"

 

 

UniqueName="Completed Date">

 

 

<HeaderStyle Width="52px" />

 

 

</telerik:GridBoundColumn>

 

 

<telerik:GridBoundColumn DataField="Cost Desc" HeaderStyle-Width="80px" HeaderText="Cost Desc"

 

 

UniqueName="Cost Desc">

 

 

<HeaderStyle Width="80px" />

 

 

</telerik:GridBoundColumn>

 

 

</Columns>

 

 

<RowIndicatorColumn>

 

 

<HeaderStyle Width="20px" />

 

 

</RowIndicatorColumn>

 

 

<ExpandCollapseColumn>

 

 

<HeaderStyle Width="20px" />

 

 

</ExpandCollapseColumn>

 

 

</MasterTableView>

 

 

<HeaderStyle Font-Size="10px" />

 

 

</telerik:RadGrid>

 

 

</telerik:RadAjaxPanel>

 


The grid is bound to a datatable:

 

Dim table As DataTable

 

table =

New DataTable("History")

 

 

Dim rCreatedDate As DataColumn = New DataColumn("Created Date")

 

rCreatedDate.DataType = System.Type.GetType(

"System.DateTime")

 

table.Columns.Add(rCreatedDate)

 

Dim rDetails As DataColumn = New DataColumn("Details")

 

rCreatedDate.DataType = System.Type.GetType(

"System.String")

 

table.Columns.Add(rDetails)

 

Dim rHandler As DataColumn = New DataColumn("Handler")

 

rCreatedDate.DataType = System.Type.GetType(

"System.String")

 

table.Columns.Add(rHandler)

 

Dim rActionType As DataColumn = New DataColumn("Action Type")

 

rCreatedDate.DataType = System.Type.GetType(

"System.String")

 

table.Columns.Add(rActionType)

 

Dim rCorrType As DataColumn = New DataColumn("Corr Type")

 

rCreatedDate.DataType = System.Type.GetType(

"System.String")

 

table.Columns.Add(rCorrType)

 

Dim rCostCode As DataColumn = New DataColumn("Cost Code")

 

rCreatedDate.DataType = System.Type.GetType(

"System.String")

 

table.Columns.Add(rCostCode)

 

Dim rCostNoUnits As DataColumn = New DataColumn("No of Units")

 

rCreatedDate.DataType = System.Type.GetType(

"System.String")

 

table.Columns.Add(rCostNoUnits)

 

Dim rCostValue As DataColumn = New DataColumn("Cost Value")

 

rCreatedDate.DataType = System.Type.GetType(

"System.String")

 

table.Columns.Add(rCostValue)

 

Dim rCompletedDate As DataColumn = New DataColumn("Completed Date")

 

rCreatedDate.DataType = System.Type.GetType(

"System.String")

 

table.Columns.Add(rCompletedDate)

 

Dim rCostDescription As DataColumn = New DataColumn("Cost Desc")

 

rCreatedDate.DataType = System.Type.GetType(

"System.String")

 

table.Columns.Add(rCostDescription)

 

 

newRow.Item(

"Created Date") = historyItem.SelectSingleNode("following-sibling::history.created_date").InnerText

 

newRow.Item(

"Details") = historyItem.SelectSingleNode("following-sibling::history.details").InnerText

 

newRow.Item(

"Handler") = historyItem.SelectSingleNode("following-sibling::history.handler").InnerText

 

newRow.Item(

"Action Type") = historyItem.SelectSingleNode("following-sibling::history.action_type").InnerText

 

newRow.Item(

"Corr Type") = historyItem.SelectSingleNode("following-sibling::history.corr_type").InnerText

 

newRow.Item(

"Cost Code") = historyItem.SelectSingleNode("following-sibling::history.cost_code").InnerText

 

newRow.Item(

"No of Units") = historyItem.SelectSingleNode("following-sibling::history.cost_no_units").InnerText

 

newRow.Item(

"Cost Value") = historyItem.SelectSingleNode("following-sibling::history.cost_value").InnerText

 

newRow.Item(

"Completed Date") = historyItem.SelectSingleNode("following-sibling::history.completed_date").InnerText

 

newRow.Item(

"Cost Desc") = historyItem.SelectSingleNode("following-sibling::history.cost-description").InnerText

 

table.Rows.Add(newRow)


 

Dim grid As RadGrid

 

grid = Page.FindControl(

"rgHistory")

 

grid.DataSource = table

grid.DataBind()


------------------------------------------------------------------------------------------

Any help would be great.

Thanks

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 29 Nov 2010, 04:39 PM
Hi Matt,

Consider the RadGrid Column Types online demo. The second RadGrid contains a DateTimeColumn with sorting enabled. Sorting is similar for all column types - your data values are sorted using default comparison for the data type.

Regards,
Pavlina
the Telerik team
Browse the vast support resources we have to jumpstart 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.
0
matt
Top achievements
Rank 1
answered on 29 Nov 2010, 04:46 PM
Hi Pavlina,

Thanks for getting back to me.

I did research the topic first and actually found that example, which is why i changed my Telerik:GridBoundColumn to a Telerik:DateTimeColumn.

Thanks,
Matt
0
Pavlina
Telerik team
answered on 01 Dec 2010, 12:21 PM
Hi Matt,

At this point to assist you further it will be best if you can provide runnable code illustrating your scenario and the issue. I will check it out and turn back to you with my findings.
 
Greetings,
Pavlina
the Telerik team
Browse the vast support resources we have to jumpstart 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
matt
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
matt
Top achievements
Rank 1
Share this question
or