c# - Sorting using a Repeater with pagination -
i have repeater , i'm using pagination. works, funny stuff sorting. first of all, if press sort button, pagination control shows twice. secondly, paginates based on default sort order. ideas might 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 [acct_list] left join [acct_grp_list] on [acct_grp_list].acct_grp_pk = [acct_list].acct_grp_fk order " + srtorder + "", con); dataset ds = new dataset(); adp.fill(ds, "tacctlist"); //pagination code set number of records loads @ time. // done speed loading, since list gets 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 asp.net side, button control looks 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 new, before added sort functionality worked fine. , pagination piece works fine sort piece went wonky. can't figure out part of pagination piece threw out of whack.
try
ds.tables["tacctlist"].defaultview.sort = "priority_rank asc";
Comments
Post a Comment