asp.net实现access数据库分页的方法
程序员文章站
2024-02-22 08:42:22
asp.net操作access数据库是常见的数据库操作应用,本文就来实例讲解一下asp.net实现access数据库分页的方法。希望对大家的asp.net程序设计能有所帮助...
asp.net操作access数据库是常见的数据库操作应用,本文就来实例讲解一下asp.net实现access数据库分页的方法。希望对大家的asp.net程序设计能有所帮助。
具体实例代码如下:
<divclass="page"id="ctrlrecordpage"> 总<asp:labelid="zpage"runat="server"text="1"></asp:label>页/ <asp:labelid="zcount"runat="server"text="0"></asp:label>条 <asp:linkbuttonid="start_button"runat="server"onclick="start_button_click">首页</asp:linkbutton> <asp:linkbuttonid="up_button"runat="server"onclick="up_button_click">上一页</asp:linkbutton> <asp:linkbuttonid="down_button"runat="server"onclick="down_button_click">下一页</asp:linkbutton> <asp:linkbutton id="end_button" runat="server" onclick="end_button_click">末页</asp:linkbutton> 每页<asp:textboxid="pagesize"runat="server"text="10"width="30px"></asp:textbox>条 当前<asp:dropdownlistid="pageing"runat="server"autopostback="true" onselectedindexchanged="pageing_selectedindexchanged"></asp:dropdownlist>页 </div> privatevoidpageing_databird(intvalue) { pageing.items.clear(); intzdatapage=convert.toint32(zpage.text); if(zdatapage>0) { for(inti=1;i<=zdatapage;i++) { pageing.items.add(i.tostring()); } } else { pageing.items.add("1"); } if(pageing.items.findbyvalue(value.tostring())!=null)pageing.selectedvalue=value.tostring(); if(zdatapage>1) { pageing.enabled=true; intdatapageing=convert.toint32(pageing.selectedvalue); if(datapageing>1) { start_button.enabled=true; up_button.enabled=true; } else { start_button.enabled=false; up_button.enabled=false; } if(datapageing<zdatapage) { down_button.enabled=true; end_button.enabled=true; } else { down_button.enabled=false; end_button.enabled=false; } } else { start_button.enabled=false; up_button.enabled=false; down_button.enabled=false; end_button.enabled=false; pageing.enabled=false; } } protectedvoidstart_button_click(objectsender,eventargse) { intdatapageing=1; if(pageing.items.findbyvalue(datapageing.tostring())!=null)pageing.selectedvalue=datapageing.tostring(); databird(); } protectedvoidup_button_click(objectsender,eventargse) { intdatapageing=convert.toint32(pageing.selectedvalue); if(datapageing>1)datapageing--; if(pageing.items.findbyvalue(datapageing.tostring())!=null)pageing.selectedvalue=datapageing.tostring(); databird(); } protectedvoiddown_button_click(objectsender,eventargse) { intdatapageing=convert.toint32(pageing.selectedvalue); intzdatapage=convert.toint32(zpage.text); if(datapageing<zdatapage)datapageing++; if(pageing.items.findbyvalue(datapageing.tostring())!=null)pageing.selectedvalue=datapageing.tostring(); databird(); } protectedvoidend_button_click(objectsender,eventargse) { intzdatapage=convert.toint32(zpage.text); if(pageing.items.findbyvalue(zdatapage.tostring())!=null)pageing.selectedvalue=zdatapage.tostring(); databird(); } protectedvoidpageing_selectedindexchanged(objectsender,eventargse) { databird(); } protectedvoiddatabird() { dc.setsql="select*fromadlistorderbycreatetimedesc"; datatabledt=dc.getdatatable(0); pageddatasourcepds=newpageddatasource(); pds.datasource=dt.defaultview; pds.allowpaging=true; intdatapagesize=10; if(convert.toint32(pagesize.text)>0)datapagesize=convert.toint32(pagesize.text); pds.pagesize=datapagesize; zcount.text=pds.datasourcecount.tostring(); zpage.text = pds.pagecount.tostring(); intzpaging=1; if(pageing.selectedindex>-1)zpaging=convert.toint32(pageing.selectedvalue); pageing_databird(zpaging); pds.currentpageindex=convert.toint32(pageing.selectedvalue)-1; listshow_repeater.datasource=pds; listshow_repeater.databind(); }
相信本文实例能对大家的asp.net程序设计带来一定的启发与灵感。感兴趣的朋友可以进一步完善本文实例,使其功能更加完善,界面更加美观。