Please lookinto my code below
<MasterTableView CommandItemStyle-Font-Names="tahoma" CommandItemStyle-Font-Size="10pt" |
HeaderStyle-BackColor="#1C5E55" ItemStyle-BackColor="LightGray" BorderColor="Gray" |
BorderWidth="1px" AllowSorting="true" AutoGenerateColumns="False"> |
<RowIndicatorColumn> |
<HeaderStyle Width="20px" /> |
</RowIndicatorColumn> |
<ExpandCollapseColumn> |
<HeaderStyle Width="20px" /> |
</ExpandCollapseColumn> |
<ItemStyle BackColor="LightGray" /> |
<HeaderStyle BackColor="#1C5E55" /> |
<CommandItemStyle Font-Names="tahoma" Font-Size="10pt" /> |
<Columns> |
<telerik:GridBoundColumn UniqueName="WorkflowType" SortExpression="WorkflowType" |
HeaderText="Workflow Type" DataField="WorkflowType"> |
</telerik:GridBoundColumn> |
</Columns> |
</MasterTableView> |
This is my code. The sort is not ascending or descending correctly for workflow column. But records are ordered in some random manner. Can any one please guide.
10 Answers, 1 is accepted

If you are automatically sort the RadGrid by setting AllowSorting property to True, then it allow users to select a sorting mode like Ascending/Decending/No sort. You can set default sort expression for the MasterTableView directly in the ASPX declaration to provide an initial sort order.
ASPX:
<MasterTableView CommandItemStyle-Font-Names="tahoma" CommandItemStyle-Font-Size="10pt" |
HeaderStyle-BackColor="#1C5E55" ItemStyle-BackColor="LightGray" BorderColor="Gray" |
BorderWidth="1px" AllowSorting="true" AutoGenerateColumns="False"> |
<SortExpressions> |
<telerik:GridSortExpression FieldName="WorkflowType" SortOrder="Ascending" /> |
</SortExpressions> |
................................. |
Thanks,
Princy.

I followed your scenario in order to replicate the issue but to no avail. However I am sending you a simple runnable project which handles the desired functionality. Please give it a try and let me know what is the difference in your scenario.
Kind regards,
Pavlina
the Telerik team

Thanks for your reply. Can you please answer my below queries
1. Grid sorting is not working ,if I have listitem as datasource to telerik grid ,. However if I convert the same list as an datatable and bind it as a datasource , the sorting is working correctly. Do the datatype of datasource matters in sorting ?
2. I have a value from database( For instance say "EDIT" , "ADD") now if I convert "ADD" in codebehind to "Sucessfully added", and bind it in grid. How to make the sort work for the converted string ( like if I sort in ascending order, I want in the order of EDIT, Sucessfully added ?
Since the SortExpression of my grid is set to my database value my asc sort is returning in the order Sucessfully added , EDIT.
Thanks
Bino
It would be best if you could open a formal support ticket and send us a simple running project that demonstrates your scenario with detailed information on the problem. We will take a look at your code, test it on our side, investigate the issues and do our best to help you.
All the best,
Pavlina
the Telerik team

I will customize and send you my sample code. Can you please tell me, if changing the value in ItemDataBound event of the grid, makes the sorting behave incorrectly?
because When I bind a proper datatable to the Grid, whithout having any ItemDataBind Event the sorting works correctly
Thanks
Bino
I think that changing the value in ItemDataBound event of the grid should not cause the sorting behave incorrectly. However, I am looking forward to receiving the requested application.
Sincerely yours,
Pavlina
the Telerik team

Thanks for your reply. Please find my code used below.
Thanks in advance for your solution
My Aspx page
<telerik:RadGrid ID="rgTopics" AutoGenerateColumns="True" runat="server" AllowPaging="true" |
PageSize="20" AllowSorting="true" OnPageIndexChanged="radgridWorkflowResults_SelectedIndexChanged" |
OnSortCommand="radgridWorkflowResults_OnSort" Skin="Web20" SelectedItemStyle-BackColor="LightBlue" |
CommandItemStyle-Font-Names="tahoma" BorderColor="White" GridLines="None" |
OnPageSizeChanged="radgridWorkflowResults_OnPageSizeChanged" OnItemDataBound="rgTopics_ItemDataBound"> |
<PagerStyle Mode="NextPrevNumericAndAdvanced" AlwaysVisible="True" ></PagerStyle> |
<SelectedItemStyle BackColor="LightBlue" /> |
<MasterTableView CommandItemStyle-Font-Names="tahoma" CommandItemStyle-Font-Size="10pt" |
HeaderStyle-BackColor="#1C5E55" ItemStyle-BackColor="LightGray" BorderColor="Gray" |
BorderWidth="1px" AutoGenerateColumns="False"> |
<RowIndicatorColumn> |
<HeaderStyle Width="20px" /> |
</RowIndicatorColumn> |
<ExpandCollapseColumn> |
<HeaderStyle Width="20px" /> |
</ExpandCollapseColumn> |
<ItemStyle BackColor="LightGray" /> |
<HeaderStyle BackColor="#1C5E55" /> |
<CommandItemStyle Font-Names="tahoma" Font-Size="10pt" /> |
<Columns> |
<telerik:GridHyperLinkColumn DataNavigateUrlFields="TopicProperties.TopicId" UniqueName="TopicTitle" |
DataNavigateUrlFormatString="~/Topic/pages/OpenTopic.aspx?TopicID={0}&view=web" HeaderText="Topic Title" |
DataTextField="TopicProperties.Title" SortExpression="TopicProperties.Title" |
Target="_blank"> |
</telerik:GridHyperLinkColumn> |
<telerik:GridBoundColumn UniqueName="Owner" SortExpression="Owner.NameInListFormat" HeaderText="Owner" |
DataField="Owner.NameInListFormat"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn UniqueName="WorkflowType" AllowSorting="true" |
HeaderText="Workflow Type" DataField="WorkflowType"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn UniqueName="State" SortExpression="WorkflowStatus" HeaderText="State" |
DataField="WorkflowStatus"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn UniqueName="PrimarySpecialty" SortExpression="TopicProperties.PrimarySpecialtyShortName" |
HeaderText="Primary<br/>Specialty" DataField="TopicProperties.PrimarySpecialtyShortName"> |
</telerik:GridBoundColumn> |
<telerik:GridDateTimeColumn UniqueName="Started" HeaderText="Workflow Started" DataField="StartDate" |
DataFormatString="{0:M/d/yyyy h:mm tt}" SortExpression="StartDate"> |
</telerik:GridDateTimeColumn> |
<telerik:GridBoundColumn UniqueName="Completed" SortExpression="FinishedDate" HeaderText="Workflow Completed" |
DataField="FinishedDate"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn UniqueName="InitialGradedDate" SortExpression="InitialGradedDate" HeaderText="Initial Graded Date" |
DataField="InitialGradedDate"> |
</telerik:GridBoundColumn> |
<telerik:GridBoundColumn UniqueName="InitialGradedDateInRange" SortExpression="InitialGradedDateInRange" HeaderText="Within Date Range" |
DataField="InitialGradedDateInRange"> |
</telerik:GridBoundColumn> |
<telerik:GridHyperLinkColumn DataNavigateUrlFields="TopicProperties.TopicId" UniqueName="TopicTitle" |
DataNavigateUrlFormatString="~/Topic/pages/TopicTaskHistory.aspx?TopicID={0}" HeaderText="History" |
Text="View" SortExpression="TopicProperties.Title" |
Target="_blank"> |
</telerik:GridHyperLinkColumn> |
</Columns> |
</MasterTableView> |
<CommandItemStyle Font-Names="tahoma" Font-Size="10pt"></CommandItemStyle> |
</telerik:RadGrid> |
This is how I bind the data to my grid
List<TopicWorkflow> result = o as List<TopicWorkflow>; |
rgTopics.DataSource = result; |
rgTopics.DataBind(); |
//some Customization in ItemdataBound event |
protected void rgTopics_ItemDataBound(object sender, GridItemEventArgs e) |
{ |
//Is it a GridDataItem |
if (e.Item.DataItem is TopicWorkflow && e.Item is GridDataItem) |
{ |
IReferenceListService referenceService = ServiceManager.Instance.GetService<IReferenceListService>(); |
TopicWorkflow findallVO = e.Item.DataItem as TopicWorkflow; |
GridDataItem dataItem = e.Item as GridDataItem; |
string linkLabel = null; |
Dictionary<TopicReviewWorkflowVO.TopicWorkflowType, string> topicTasks = referenceService.GetTopicWorkflowTaskTypes(); |
Dictionary<TopicReviewWorkflowVO.TopicWorkflowStatus, string> workflowStatuses = referenceService.GetTopicWorkflowStatuses(); |
if (findallVO.WorkflowType == TopicReviewWorkflowVO.TopicWorkflowType.EDT) |
{ |
linkLabel = string.Format("<i>{0}</i>", topicTasks[findallVO.WorkflowType]); |
} |
else if (findallVO.WorkflowType == TopicReviewWorkflowVO.TopicWorkflowType.MCB) |
{ |
linkLabel = string.Format( |
"<a href='{0}/topic/Lists/Topic%20Approval%20Tasks/DispForm.aspx?ID={1}' target='_utdGraphicEdit'>{2}</a>", |
ConfigUtil.ReadAppSetting(Constants.UTD_SITE_URL), |
findallVO.WorkflowId, |
topicTasks[findallVO.WorkflowType] |
); |
} |
else |
{ |
linkLabel = string.Format("<a href='{0}/topic/pages/TopicReviewWorkflow.aspx?WorkflowID={1}' target='_blank'>{2}</a>", |
ConfigUtil.ReadAppSetting(Constants.UTD_SITE_URL), |
findallVO.WorkflowId, |
topicTasks[findallVO.WorkflowType] |
); |
} |
dataItem["WorkflowType"].Text = linkLabel; |
} |
} |
Note that advanced features like sorting, paging, filtering etc. are not supported with simple data-binding calling DataBind(). Please switch to advance binding with NeedDataSource event handling using the same code without the DataBind() call and let me know how it goes.
Kind regards,
Pavlina
the Telerik team

Converting my list to datatable solved my issue..
Thanks
Bino