Reputation: 519
I am populating a DropdownLIst from an ObjectDataSource. The ObjectDataSource gets it values from a service. The service delivers the results unsorted. Is there way I can sort the by DataTextField before the data is bound to the DropdownList? I feel like there should be a way to do this within the client-side here, but I don't know how. Suggestions please? (.net 4.5)
<asp:DropDownList ID="AffiliationDropDownList" runat="server"
ClientIDMode="Static" Width="200px"
DataSourceID="AffiliationObjectDataSource"
DataTextField="AffiliateName"
DataValueField="AffiliateID"
AppendDataBoundItems="true"
AutoPostBack="false" >
<asp:ListItem Text="All Affiliations" Value="" />
</asp:DropDownList>
<asp:ObjectDataSource runat="server" ID="AffiliationObjectDataSource"
SelectMethod="RetrieveActiveAffiliations"
TypeName="OnlineVolunteerApplication.Data.VolunteerService.VolunteerServiceClient" >
</asp:ObjectDataSource>
Upvotes: 1
Views: 529
Reputation: 172428
You can try doing this:-
DataView defaultView = dataSource.Tables[0].DefaultView;
DataTable dt = getData();
dt.DefaultView.Sort= "UserName DESC";
Upvotes: 0