ASP DataSource选择订购

时间:2012-07-11 12:22:57

标签: asp.net

以下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>

1 个答案:

答案 0 :(得分: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