This topic presents how to enable sorting for GridHyperLinkColumn/GridTemplateColumn. To summarize, you need to set appropriate SortExpressions for those columns and DataTextField (for the hyperlink column) and binding expression (for the template column). The code below represents sample implementation:
| ASPX/ASCX |
Copy Code |
<rad:RadGrid ID="RadGrid1" DataSourceID="AccessDataSource1" AllowSorting="True" Skin="WinXP" runat="server" Width="400px"> <MasterTableView AutoGenerateColumns="false" AllowSorting="true"> <Columns> <rad:GridHyperLinkColumn DataTextField="Country" NavigateUrl="http://www.telerik.com" HeaderText="Country" SortExpression="Country" /> <rad:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="City" SortExpression="City"> <ItemTemplate> <%# Eval("City") %> </ItemTemplate> </rad:GridTemplateColumn> </Columns> </MasterTableView> </rad:RadGrid> <br /> <asp:AccessDataSource ID="AccessDataSource1" DataFile="~/Grid/Data/Access/Nwind.mdb" SelectCommand="SELECT TOP 10 Country, City FROM Customers" runat="server"></asp:AccessDataSource> |
When using a GridTemplateColumn or other custom command buttons to apply sorting, you should set CommandName to Sort and sort-expression as CommandArgument for that header button.
| ASPX/ASCX |
Copy Code |
|
<rad:GridTemplateColumn SortExpression="CompanyName">
<HeaderTemplate>
<asp:Button id="Button42" Text="GridTemplateColumn" Title="Sort by CompanyName" CommandName='Sort' CommandArgument='CompanyName' runat="server" />
</HeaderTemplate>
... |

In this case Telerik RadGrid will handle the sorting and put the sorting indicator image automatically in the column header.