0

下面的 ASP 代码按字段 Principal_ID 的顺序显示数据,我想按 SchoolName 的字母顺序进行。有谁知道我怎么能做到这一点

<asp:Panel ID="show_pnl" runat="server" runat="server"  GroupingText="Show Principal" Width="100%" Font-Names="verdana"
            Font-Size="Small" BackColor="white" align=center" BorderColor="white" BorderPadding="0" BorderStyle="none" BorderWidth="0px">>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="ShowPrincipals_DS"
                DataKeyNames="SchoolName" CssClass="mGrid" PagerStyle-CssClass="pgr" AlternatingRowStyle-CssClass="alt"
                Font-Size="Small" Font-Names="verdana" Height="100%" Width="100%" AutoGenerateDeleteButton="True">
                <Columns>
                    <asp:BoundField DataField="Principal_ID" HeaderText="Principal ID" SortExpression="Principal_ID" />
                    <asp:BoundField DataField="FirstName" HeaderText="First Name" SortExpression="FirstName" />
                    <asp:BoundField DataField="LastName" HeaderText="Last Name" SortExpression="LastName" />
                    <asp:BoundField DataField="UserName" HeaderText="User Name" SortExpression="UserName" />
                    <asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
                    <asp:BoundField DataField="SchoolName" HeaderText="School Name" SortExpression="SchoolName" />
                </Columns>
                <PagerStyle CssClass="pgr" />
                <EmptyDataTemplate>
                    No Data Available
                </EmptyDataTemplate>
                <AlternatingRowStyle CssClass="alt" />
            </asp:GridView>
            <asp:AccessDataSource ID="ShowPrincipals_DS" runat="server" DataFile="~/App_Data/MockCourt_db.mdb"
                SelectCommand="SELECT tbl_Principal.Principal_ID, tbl_Principal.FirstName, tbl_Principal.LastName, tbl_Principal.UserName, tbl_Principal.Email, tbl_school.SchoolName FROM (tbl_Principal INNER JOIN tbl_school ON tbl_Principal.School_ID = tbl_school.School_ID)"
                DeleteCommand="DELETE FROM [tbl_Principal] WHERE ([Principal_ID] = @Principal_Id)">
                <DeleteParameters>
                    <asp:Parameter Name="Principal_ID" Type="int32" />
                </DeleteParameters>
            </asp:AccessDataSource>
        </asp:Panel>
4

1 回答 1

2

ORDER BY只需在现有SELECT查询中添加一个子句:

SELECT tbl_Principal.Principal_ID, tbl_Principal.FirstName, tbl_Principal.LastName, tbl_Principal.UserName, tbl_Principal.Email, tbl_school.SchoolName FROM (tbl_Principal INNER JOIN tbl_school ON tbl_Principal.School_ID = tbl_school.School_ID) ORDER BY tbl_school.SchoolName
于 2012-07-11T12:25:30.690 回答