This is a migrated thread and some comments may be shown as answers.

Cannot sort RadDropDownList within EditItemTemplate.

3 Answers 58 Views
DropDownList
This is a migrated thread and some comments may be shown as answers.
Dale
Top achievements
Rank 1
Dale asked on 23 Oct 2015, 07:00 PM

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">
<ItemTemplate>
<%#DataBinder.Eval(Container.DataItem, "DepartmentID")%>
</ItemTemplate>
<EditItemTemplate>
<telerik:RadDropDownList runat="server" ID="RadDropDownList1" DataTextField="DepartmentID"
DataValueField="DepartmentID" DataSourceID="SqlDataSource1" SelectedValue='<%#Bind("DepartmentID")%>'>
</telerik:RadDropDownList>
</EditItemTemplate>
</telerik:GridTemplateColumn>

 

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

What am I missing in my code?

 

Thank you, Dale

 

3 Answers, 1 is accepted

Sort by
0
Accepted
Konstantin Dikov
Telerik team
answered on 28 Oct 2015, 09:35 AM
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"
        DataValueField="CustomerID">
    </telerik:RadDropDownList>
 
<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.
 

Regards,
Konstantin Dikov
Telerik
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
0
Dale
Top achievements
Rank 1
answered on 28 Oct 2015, 02:21 PM

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, 

 

0
Dale
Top achievements
Rank 1
answered on 18 Nov 2015, 05:51 PM
Thanks, it is working now. 
Tags
DropDownList
Asked by
Dale
Top achievements
Rank 1
Answers by
Konstantin Dikov
Telerik team
Dale
Top achievements
Rank 1
Share this question
or