Sorting using a Repeater with pagination

568 views Asked by At

I have a repeater and I'm using pagination. It works, but it does funny stuff with my sorting. First of all, if I press the Sort button, my pagination control shows up twice. Secondly, it paginates based on the default sort order. Any ideas what might be wrong?

    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();
    }

And on the ASP.Net side, the button control looks like this:

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

The pagination piece is new, but before it was added the sort functionality worked fine. And now the pagination piece works fine but the sort piece went wonky. I can't figure out which part of the pagination piece threw it out of whack.

1

There are 1 answers

2
wtfidgafmfgtfooh On

try

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