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