c# - Pagination code issue -
i have written below lines of code acconmplishing pagination in asp.net using repeater control as
<asp:linkbutton id="linkbutton1" runat="server" causesvalidation="false" onclick="pagenexte_click" data-rel="tooltip" data-original-title="previous page.">«</asp:linkbutton> <asp:repeater id="rptpager" onitemdatabound="rptpager_itemdatabound" runat="server"> <itemtemplate> <asp:linkbutton id="lnkpage" runat="server" text='<%#eval("text") %>' commandargument='<%# eval("value") %>' enabled='<%# eval("enabled") %>' onclick="page_changed"></asp:linkbutton> </itemtemplate> </asp:repeater> <asp:linkbutton id="linkbutton3" runat="server" causesvalidation="false" onclick="pagenext_click" data-rel="tooltip" data-original-title="next page.">» </asp:linkbutton> <asp:linkbutton id="linkbutton2" runat="server" causesvalidation="false" onclick="imgnext_click" data-rel="tooltip" data-original-title="next page." visible="false"> » </asp:linkbutton>
in cs file
public void updatepagelables(int apagecount) { if (!page.ispostback) { session["pages"] = null; } pagecount = (int)math.ceiling((decimal)apagecount / pagesize); int recordcount = pagecount; if (pagesizechanged != null) { hiddenfield hd = new hiddenfield(); int current; current = pageindex; int pre; int next; double dblpagecount = (double)((decimal)recordcount / decimal.parse(lstpagesize.selectedvalue)); int pagecount = pagecount; list<listitem> pages = new list<listitem>(); if (pagecount > 0) { // pages.add(new listitem("first", "1", pageindex > 1)); current = pageindex; pre = --pageindex; pageindex = current; // pages.add(new listitem("previous", pre.tostring(), pageindex > 1)); (int = 1; <= apagecount; i++) { if (i <= 5) { pages.add(new listitem(i.tostring(), i.tostring(), != pageindex)); } } int currentpage = pageindex; next = ++pageindex; pageindex = currentpage; //pages.add(new listitem("next", next.tostring(), pageindex < pagecount)); // pages.add(new listitem("last", pagecount.tostring(), pageindex < pagecount)); hd.value = (pre.tostring()); } if (session["pages"] != null) { rptpager.datasource = session["pages"]; rptpager.databind(); } else { rptpager.datasource = pages; rptpager.databind(); } session["lastnumber"] = 5; session["pagecount"] = apagecount; session["orignalpages"] = pages; } } protected void pagenext_click(object sender, eventargs e) { list<listitem> pages = new list<listitem>(); int pagecount = convert.toint32(session["pagecount"].tostring()); int lastnumber = convert.toint32(session["lastnumber"].tostring()); if (lastnumber > pagecount) { session["lastnumber"] = 1; lastnumber = 1; session["pagecount"] = pagecount; session["orignalpages"] = pages; } int limit = lastnumber + 5; (int = lastnumber; <= pagecount; i++) { if (i <= limit) { pages.add(new listitem(i.tostring(), i.tostring(), != pageindex)); } else { rptpager.datasource = session["orignalpages"]; rptpager.databind(); } } session["lastnumber"] = limit; session["pagecount"] = pagecount; session["pages"] = pages; rptpager.datasource = pages; rptpager.databind(); } protected void pagenexte_click(object sender, eventargs e) { list<listitem> pages = new list<listitem>(); int pagecount = convert.toint32(session["pagecount"].tostring()); int lastnumber = convert.toint32(session["lastnumber"].tostring()); if (lastnumber > pagecount) { session["lastnumber"] = pagecount - 5; lastnumber = pagecount - 5; session["pagecount"] = pagecount; session["orignalpages"] = pages; } else { session["lastnumber"] = 1; lastnumber = 1; session["pagecount"] = pagecount; session["orignalpages"] = pages; } int limit = lastnumber + 5; (int = lastnumber; <= pagecount; i++) { if (i <= limit && i>0) { pages.add(new listitem(i.tostring(), i.tostring(), != pageindex)); } else { //rptpager.datasource = session["orignalpages"]; //rptpager.databind(); } } session["lastnumber"] = limit; session["pagecount"] = pagecount; session["pages"] = pages; rptpager.datasource = pages; rptpager.databind(); }
its working fine not display page numbers required. want should display "1 2 3 4 5 " clicking on next button, should display "6 7 8 9 10" again clicking on next button "11 12 13 14 15".... on. below code generating page numbers "1 2 3 4 5" clicking on next button "5 6 7 8 9 10" , 10 11 12 13 14 15 , on... please me !!! me improve code previous button also...
you can use "datatable" javascript functionality problem. please refer https://www.datatables.net/.
in need give table id in below code.
$(document).ready(function(){ $('#mytable').datatable(); });
Comments
Post a Comment