使用带分页的Repeater进行排序

时间:2015-06-25 15:59:10

标签: c# asp.net pagination repeater code-behind

我有一个转发器,我正在使用分页。它有效,但它对我的排序很有趣。首先,如果我按下排序按钮,我的分页控件会出现两次。其次,它基于默认排序顺序进行分页。什么想法可能是错的?

    protected void btnSort_Click(object sender, EventArgs e)
    {
        Show_Data();
    }

    public void Show_Data()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PBRConnectionString"].ConnectionString);
        string srtOrder = cboSortBy.Text;
        SqlDataAdapter adp = new SqlDataAdapter("select [ACCT_LIST].*, [ACCT_GRP_LIST].ACCT_GRP from [ACCT_LIST] LEFT JOIN [ACCT_GRP_LIST] on [ACCT_GRP_LIST].ACCT_GRP_PK = [ACCT_LIST].ACCT_GRP_FK ORDER BY " + srtOrder + "", con);
        DataSet ds = new DataSet();
        adp.Fill(ds, "TAcctList");

        //Pagination code so only a set number of records loads at a time.
        //  Done to speed up the loading, since this list gets really long.
        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = ds.Tables["TAcctList"].DefaultView;
        pds.AllowPaging = true;
        pds.PageSize = 20;

        int currentPage;

        if (Request.QueryString["page"] != null)
        {
            currentPage = Int32.Parse(Request.QueryString["page"]);
        }
        else
        {
            currentPage = 1;
        }

        pds.CurrentPageIndex = currentPage - 1;
        Label1.Text = "Page " + currentPage + " of " + pds.PageCount;

        if (!pds.IsFirstPage)
        {
            MenuItem itemMessage = NavMenu.FindItem("First");
            itemMessage.NavigateUrl = Request.CurrentExecutionFilePath + "?page=1";
        }

        AcctRepeater.DataSource = pds;
        AcctRepeater.DataBind();

        CreatePagingControl(pds.PageCount, pds.CurrentPageIndex);
        // End of Pagination code

        con.Close();
    }

在ASP.Net方面,按钮控件如下所示:

<table>
<tr>
    <td width="150"><asp:DropDownList ID="cboSortBy" runat="server" Width="120">
                                <asp:ListItem Value="StatusText">Benefit Type</asp:ListItem>
                                <asp:ListItem Value="PRIORITY_RANK">Priority Rank</asp:ListItem>
                                <asp:ListItem Value="ACTIVE_FLG">Active Flag</asp:ListItem>
                                </asp:DropDownList></td>
    <td width="180"><asp:Button ID="btnSort" runat="server" 
        Text="Sort" Width="121px" onclick="btnSort_Click" /></td>
</tr>
</table>

分页是新的,但在添加之前,排序功能运行良好。现在这个分页工作得很好,但是这个分类很难实现。我无法弄清楚这个分页的哪一部分让它摆脱了重击。

1 个答案:

答案 0 :(得分:0)

ds.Tables["TAcctList"].DefaultView.Sort = "PRIORITY_RANK ASC";