按顺序显示ASP下拉列表

时间:2012-07-17 14:02:28

标签: asp.net

以下代码是一个从数据库中显示学校的下拉框,是否仍然按字母顺序显示这些学校?

<td align="right" style="text-align: right; width: 170px;">
    <asp:Label ID="School_lbl" runat="server" AssociatedControlID="School" 
        Text="School:"></asp:Label>
</td>
<td style="width: 206px">
    <asp:DropDownList ID="School" runat="server" DataSourceID="School_DS" 
        DataTextField="SchoolName" AppendDataBoundItems="True"
        DataValueField="SchoolName" Font-Names="verdana" Width="185px" 
        AutoPostBack="True"
        OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">

        <asp:ListItem Selected="True">-- Select --</asp:ListItem>
    </asp:DropDownList>
    <asp:AccessDataSource ID="School_DS" runat="server" 
        DataFile="~/App_Data/MockCourt_db.mdb"
        SelectCommand="SELECT [SchoolName] FROM [tbl_school]">
    </asp:AccessDataSource>
    &nbsp;&nbsp;
</td>

1 个答案:

答案 0 :(得分:3)

将您的选择命令更改为:

SELECT [SchoolName] FROM [tbl_school] ORDER BY [SchoolName] ASC