Cannot sort RadDropDownList within EditItemTemplate.

4 posts, 1 answers
  1. Dale
    Dale avatar
    15 posts
    Member since:
    Sep 2015

    Posted 23 Oct 2015 Link to this post

    Hello, thanks for looking at my question.  I have a popup ​Add Record window, one of the fields to select is a RadDropDownList that is populated by the Department ID column from the database.   The items in the list are not sorted and I would like them sorted in order for the user to find he needed ID faster.

    The RadDropDownList is within an EditItemTemplate  that is within a  GridTemplateColumn.


    <telerik:GridTemplateColumn HeaderText="DepartmentID" ItemStyle-Width="240px">
    <%#DataBinder.Eval(Container.DataItem, "DepartmentID")%>
    <telerik:RadDropDownList runat="server" ID="RadDropDownList1" DataTextField="DepartmentID"
    DataValueField="DepartmentID" DataSourceID="SqlDataSource1" SelectedValue='<%#Bind("DepartmentID")%>'>


    I have tried AllowSorting, SortExpression on the RadDropDownList and they did not work.

    What am I missing in my code?


    Thank you, Dale


  2. Answer
    Konstantin Dikov
    Konstantin Dikov avatar
    2115 posts

    Posted 28 Oct 2015 Link to this post

    Hi Dale,

    The RadDropDownList control does not have AllowSorting, nor SortExpression properties and sorting the items should be performed on the data source. In your scenario, since you are providing the data through the DataSourceID property, you could set the order in the Select command of your SqlDataSource control:
    <telerik:RadDropDownList ID="RadDropDownList2" runat="server" Width="220px"
            DropDownHeight="200" DataSourceID="SqlDataSource1" DataTextField="ContactName" DefaultMessage="Select Customer"
    <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    ProviderName="System.Data.SqlClient" SelectCommand="SELECT [CustomerID], [ContactName] FROM [Customers] ORDER By ContactName"></asp:SqlDataSource>

    Another option is to handle the server-side OnDataBound event of the RadDropDownList and sort the Items collection:
    protected void RadDropDownList2_DataBound(object sender, EventArgs e)
        (sender as RadDropDownList).Items.Sort(x => x.Text);

    Hope this helps.

    Konstantin Dikov
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Dale
    Dale avatar
    15 posts
    Member since:
    Sep 2015

    Posted 28 Oct 2015 in reply to Konstantin Dikov Link to this post

    Hi Konstantin, thank you for the reply.  I now have it working, I did it the way you suggested by the sql statement on the data source.  All that had to be done was to add the ORDER BY clause.

    I asked the question as the RadGrid has a lot of features and I thought I not found one regarding my issue.

    Thank you for your time.  Dale, 


  4. Dale
    Dale avatar
    15 posts
    Member since:
    Sep 2015

    Posted 18 Nov 2015 in reply to Konstantin Dikov Link to this post

    Thanks, it is working now. 
Back to Top