synapse88
asked on
How To Sort Drop Down List - ASP.NET 2.0, VB.NET
Please check the code below and tell me how to modify so the county drop list will be sorted by a-z.
Currently the list is being ordered by the identity field which isn't even remotely alphabetical. The table which has the data for the drop down list just has two columns, the identity field (an int), and a "name" field which is what i'm trying to sort the list by.
Thanks for any ideas/info. There is no mention of the drop down's ID in the VB code behind page, but I can add some code there if that is the best way to accomplish this.
Currently the list is being ordered by the identity field which isn't even remotely alphabetical. The table which has the data for the drop down list just has two columns, the identity field (an int), and a "name" field which is what i'm trying to sort the list by.
Thanks for any ideas/info. There is no mention of the drop down's ID in the VB code behind page, but I can add some code there if that is the best way to accomplish this.
<!--Data Source for the entire form-->
<asp:SqlDataSource ID="sqlLocation" runat="server" ConnectionString="<%$ ConnectionStrings:ConnString %>"
SelectCommand="SELECT * FROM Locations">
</asp:SqlDataSource>
<!--Data Source for the County Drop Down-->
<asp:SqlDataSource ID="sqlCounties" runat="server" ConnectionString="<%$ ConnectionStrings:ConnString %>"
SelectCommand="SELECT * FROM Counties ORDER BY name">
</asp:SqlDataSource>
.
.
.
<!-- Actual County Drop Down-->
<asp:DropDownList ID="cboCounty" runat="server" CssClass="TextBox" AppendDataBoundItems="true"
DataSourceID="sqlCounties" DataTextField="name" DataValueField="identity"
SelectedValue='<%# Bind("county") %>' >
<asp:ListItem Value="">Not Entered</asp:ListItem>
</asp:DropDownList>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Is there any place in your code-behind that modifies the SelectCommand before you bind the drop down list?
Also, what if you take out this line SelectedValue='<%# Bind("county") %>'?
Also, what if you take out this line SelectedValue='<%# Bind("county") %>'?
synapse88,
This is a long shot, but have you tried it without specifying the CssClass?
This is a long shot, but have you tried it without specifying the CssClass?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Another try. Change your SelectCommand to this:
SelectCommand="SELECT [name], identity FROM Counties ORDER BY [name]
"name" is a keyword in SQL, so try to use bracket around it.
SelectCommand="SELECT [name], identity FROM Counties ORDER BY [name]
"name" is a keyword in SQL, so try to use bracket around it.
ASKER
I got it figured out, it was just a simple error I made when testing my updates...unrelated to the actual code.
I'll split the points since you were both quite helpful.
I'll split the points since you were both quite helpful.
ASKER