Telerik is a leading vendor of ASP.NET AJAX, ASP.NET MVC, Silverlight, WinForms and WPF controls and components, as well as .NET Reporting, .NET ORM , .NET CMS, Code Analysis, Mocking, Team Productivity and Automated Testing Tools. Building on its expertise in interface development and Microsoft technologies, Telerik helps customers build applications with unparalleled richness, responsiveness and interactivity. Telerik products help thousands of companies to be more productive and deliver reliable applications under budget and on time.
Version Q1 2012 released 04/11/2012
select

Grid / Programmatic Sorting

Example Configuration
Working with RadGrid Programmatic Sorting feature
Select field name: Select sort order:
Add sort expression
 
Allow multi-column sorting:

Country CityCompany NameContact NameContact Title
 Page 1 of 10, items 1 to 10 of 91.
ArgentinaBuenos AiresCactus Comidas para llevarPatricio SimpsonSales Agent
ArgentinaBuenos AiresOcéano Atlántico Ltda.Yvonne MoncadaSales Agent
ArgentinaBuenos AiresRancho grandeSergio GutiérrezSales Representative
AustriaGrazErnst HandelRoland MendelSales Manager
AustriaSalzburgPiccolo und mehrGeorg PippsSales Manager
BelgiumBruxellesMaison DeweyCatherine DeweySales Agent
BelgiumCharleroiSuprêmes délicesPascale CartrainAccounting Manager
BrazilSao PauloComércio MineiroPedro AfonsoSales Associate
BrazilSao PauloFamilia ArquibaldoAria CruzMarketing Assistant
BrazilCampinasGourmet LanchonetesAndré FonsecaSales Associate




First nameLast name
NancyDavolio
AndrewFuller
JanetLeverling
MargaretPeacock
StevenBuchanan
MichaelSuyama
RobertKing
LauraCallahan
AnneDodsworth


  • Demo instructions first grid:

    • Make your choice in the configuration section and click the button to apply / clear sorting.

    Demo instructions second grid:

    • Click the "First Name" column to sort by string length
    • Click the "Last Name" column to sort descending on first click

Source Code

C# VB.NET
Show code in new window Demo isolation steps
  • <%@ Page Language="vb" AutoEventWireup="false" Inherits="Telerik.GridExamplesVBNET.Programming.Sort.DefaultVB"
        CodeFile="DefaultVB.aspx.vb" %>

    <%@ Register TagPrefix="telerik" Namespace="Telerik.QuickStart" %>
    <%@ Register TagPrefix="telerik" TagName="Header" Src="~/Common/Header.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="HeadTag" Src="~/Common/HeadTag.ascx" %>
    <%@ Register TagPrefix="telerik" TagName="Footer" Src="~/Common/Footer.ascx" %>
    <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/tr/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <telerik:HeadTag runat="server" ID="Headtag2"></telerik:HeadTag>
        <!-- custom head section -->
        <link href="../../Styles/default/Styles.css" rel="stylesheet" type="text/css" />
        <!-- end of custom head section -->
    </head>
    <body class="BODY">
        <form runat="server" id="mainForm" method="post">
        <telerik:Header runat="server" ID="Header1" NavigationLanguage="VB"></telerik:Header>
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server" />
        <!-- content start -->
        <telerik:ConfiguratorPanel runat="server" ID="ConfigurationPanel1" Expanded="true">
            <div class="title">
                Working with RadGrid Programmatic Sorting feature</div>
            <div class="module">
                <table id="Table1" cellspacing="1" cellpadding="1" border="0" style="width: 500px;
                    height: 0px">
                    <tr>
                        <td>
                        </td>
                        <td>
                            Select&nbsp;field name:
                        </td>
                        <td>
                            Select sort order:
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Add sort expression
                        </td>
                        <td>
                            <asp:DropDownList ID="DropDownList3" runat="server">
                                <asp:ListItem Value="Country">Country</asp:ListItem>
                                <asp:ListItem Value="City">City</asp:ListItem>
                                <asp:ListItem Value="CompanyName">CompanyName</asp:ListItem>
                                <asp:ListItem Value="ContactName">ContactName</asp:ListItem>
                                <asp:ListItem Value="ContactTitle">ContactTitle</asp:ListItem>
                            </asp:DropDownList>
                        </td>
                        <td>
                            <asp:DropDownList ID="DropDownList2" runat="server">
                                <asp:ListItem Value="Ascending" Selected="True">Ascending</asp:ListItem>
                                <asp:ListItem Value="Descending">Descending</asp:ListItem>
                                <asp:ListItem Value="None">No Sort</asp:ListItem>
                            </asp:DropDownList>
                        </td>
                        <td>
                            <asp:Button CssClass="button" ID="btnAddExpression" runat="server" Text="Add"></asp:Button>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            &nbsp;
                        </td>
                        <td>
                        </td>
                        <td>
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            Allow multi-column sorting:
                        </td>
                        <td>
                            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
                                <asp:ListItem Value="True" Selected="True">True</asp:ListItem>
                                <asp:ListItem Value="False">False</asp:ListItem>
                            </asp:DropDownList>
                        </td>
                        <td>
                            <asp:Button CssClass="button" ID="Clear" runat="server" Text="Remove sorting"></asp:Button>
                        </td>
                        <td>
                        </td>
                    </tr>
                </table>
            </div>
        </telerik:ConfiguratorPanel>
        <br />
        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="DropDownList1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="btnAddExpression">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="Clear">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
                <telerik:AjaxSetting AjaxControlID="RadGrid2">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid2" LoadingPanelID="RadAjaxLoadingPanel1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
        <telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
        </telerik:RadAjaxLoadingPanel>
        <telerik:RadGrid ID="RadGrid1" DataSourceID="SqlDataSource1" runat="server" PageSize="10"
            AllowSorting="True" AllowMultiRowSelection="True" AllowPaging="True" AutoGenerateColumns="False"
            GridLines="None">
            <MasterTableView AllowMultiColumnSorting="true">
                <Columns>
                    <telerik:GridBoundColumn SortExpression="Country" HeaderText="Country" HeaderButtonType="TextButton"
                        DataField="Country">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="City" HeaderText="City" HeaderButtonType="TextButton"
                        DataField="City">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="CompanyName" HeaderText="Company Name" HeaderButtonType="TextButton"
                        DataField="CompanyName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="ContactName" HeaderText="Contact Name" HeaderButtonType="TextButton"
                        DataField="ContactName">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn SortExpression="ContactTitle" HeaderText="Contact Title"
                        HeaderButtonType="TextButton" DataField="ContactTitle">
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
            <PagerStyle Mode="NumericPages" />
        </telerik:RadGrid>
        <br />
        <br />
        <hr />
        <br />
        <telerik:RadGrid ID="RadGrid2" runat="server" AllowSorting="True" AutoGenerateColumns="False"
            GridLines="None">
            <MasterTableView AllowCustomSorting="true">
                <Columns>
                    <telerik:GridBoundColumn HeaderText="First name" HeaderButtonType="TextButton" DataField="FirstName" />
                    <telerik:GridBoundColumn HeaderText="Last name" HeaderButtonType="TextButton" DataField="LastName"
                        SortAscImageUrl="Img/SortDesc.gif" SortDescImageUrl="Img/SortAsc.gif" />
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>
        <asp:SqlDataSource ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
            ProviderName="System.Data.SqlClient" SelectCommand="SELECT * FROM Customers"
            runat="server"></asp:SqlDataSource>
        <br />
        <!-- content end -->
        <telerik:Footer runat="server" ID="Footer1" AdditionalCodeViewerFiles="~/Grid/Examples/Styles/default/Styles.css"></telerik:Footer>
        </form>
    </body>
    </html>

Get more than expected!

Take your time to truly experience the power of RadControls for ASP.NET AJAX with a free 60-day trial backed up by Telerik’s unlimited dedicated support.

Download your RadControls for ASP.NET AJAX trial and jumpstart your development with the available Getting Started resources.

If you have any questions, do not hesitate to contact us at sales@telerik.com.

Copyright 2002-2012 © Telerik. All right reserved
Telerik Inc, 201 Jones Rd, Waltham, MA 02451