当我对筛选后的搜索结果进行排序时,我的gridview显示所有已排序的

时间:2013-03-15 17:08:20

标签: c# asp.net sql

我有一个gridview,当我搜索一个特定的字符串时,我对我的过滤结果进行排序,但是gridview显示所有已排序,我丢失了我的过滤结果。任何想法?

ASP:

        <asp:GridView ID="GridViewWinners" runat="server" AutoGenerateColumns="False" 
            CellPadding="4" DataKeyNames="PlayerID" DataSourceID="SqlDataSource4" ForeColor="#333333" 
            GridLines="Horizontal" Width="858px" 
            onselectedindexchanged="GridViewWinners_SelectedIndexChanged" 
            AllowSorting="True" Visible="False">
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
            <Columns>
                <asp:CommandField ShowSelectButton="True" />
                <asp:BoundField DataField="PlayerID" HeaderText="PlayerID" ReadOnly="True" 
                    SortExpression="PlayerID" Visible="False" />
                <asp:BoundField DataField="LastName" HeaderText="Last Name" 
                    SortExpression="LastName" />
                <asp:BoundField DataField="FirstName" HeaderText="First Name" 
                    SortExpression="FirstName" />
                <asp:BoundField DataField="UserName" HeaderText="Login" 
                    SortExpression="UserName" />
                <asp:BoundField DataField="ClubNumber" HeaderText="Club Number" 
                    SortExpression="ClubNumber" />
                <asp:BoundField DataField="DOB" HeaderText="DOB" SortExpression="DOB" />
            </Columns>
            <EditRowStyle BackColor="#999999" />
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <SortedAscendingCellStyle BackColor="#E9E7E2" />
            <SortedAscendingHeaderStyle BackColor="#506C8C" />
            <SortedDescendingCellStyle BackColor="#FFFDF8" />
            <SortedDescendingHeaderStyle BackColor="#6F8DAE" />
        </asp:GridView>

<asp:SqlDataSource ID="SqlDataSource4" runat="server" 
                ConnectionString="<%$ ConnectionStrings:GameCenterPrizesConnectionString1 %>" 
                DeleteCommand="DELETE FROM [Players] WHERE [PlayerID] = @PlayerID" 
                InsertCommand="INSERT INTO [Players] ([UserName], [ClubNumber], [FirstName], [LastName], [DOB]) VALUES (@UserName, @ClubNumber, @FirstName, @LastName, @DOB)" 
                ProviderName="<%$ ConnectionStrings:GameCenterPrizesConnectionString1.ProviderName %>" 
                SelectCommand="SELECT [PlayerID], [UserName], [ClubNumber], [FirstName], [LastName], [DOB] FROM [Players]" 
                UpdateCommand="UPDATE [Players] SET [UserName] = @UserName, [ClubNumber] = @ClubNumber, [FirstName] = @FirstName, [LastName] = @LastName, [DOB] = @DOB WHERE [PlayerID] = @PlayerID">
            <DeleteParameters>
                <asp:Parameter Name="PlayerID" Type="Int64" />
            </DeleteParameters>
            <InsertParameters>
                <asp:Parameter Name="UserName" Type="String" />
                <asp:Parameter Name="ClubNumber" Type="String" />
                <asp:Parameter Name="FirstName" Type="String" />
                <asp:Parameter Name="LastName" Type="String" />
                <asp:Parameter Name="DOB" Type="DateTime" />
            </InsertParameters>
            <UpdateParameters>
                <asp:Parameter Name="UserName" Type="String" />
                <asp:Parameter Name="ClubNumber" Type="String" />
                <asp:Parameter Name="FirstName" Type="String" />
                <asp:Parameter Name="LastName" Type="String" />
                <asp:Parameter Name="DOB" Type="DateTime" />
                <asp:Parameter Name="PlayerID" Type="Int64" />
            </UpdateParameters>
        </asp:SqlDataSource>

排序前: http://tinypic.com/view.php?pic=j82tcx&s=6

排序后

http://tinypic.com/view.php?pic=rvcz07&s=6

1 个答案:

答案 0 :(得分:0)

gridview控件实际上不进行排序,它使用数据源控件对数据进行排序。 gridview控件将排序表达式传递给数据源控件,如果数据源控件能够这样做,则数据源控件将根据表达式进行排序。

http://msdn.microsoft.com/en-us/library/hwf94875.aspx

希望这会有所帮助。 --Doc