ASP.NET GridView的Bootstrap分页样式
程序员文章站
2023-11-22 10:35:46
本文实例为大家分享了gridview的bootstrap分页样式,供大家参考,具体内容如下
revenue.cs收入类,包括实体模型和业务逻辑
public...
本文实例为大家分享了gridview的bootstrap分页样式,供大家参考,具体内容如下
revenue.cs收入类,包括实体模型和业务逻辑
public class revenue { public revenue(string country, string revenue, string salesmanager, string year) { this.country = country; this.revenue = revenue; this.salesmanager = salesmanager; this.year = year; } public revenue() { } public string country { get; set; } public string revenue { get; set; } public string salesmanager { get; set; } public string year { get; set; } public list<revenue> getrevenuedetails(int pagenumber,int maxrecords) { list<revenue> lstrevenue = new list<revenue>(); string filename = httpcontext.current.server.mappath("~/app_data/country_revenue.csv"); int startrecord = (pagenumber * maxrecords) - maxrecords; if (file.exists(filename)) { ienumerable<int> range = enumerable.range(startrecord, maxrecords); ienumerable<string> lines = getfilelines(filename, range); foreach (string line in lines) { string[] row = line.split(','); lstrevenue.add(new revenue(row[0], row[1], row[2], row[3])); } } return lstrevenue; } public static ienumerable<string> getfilelines(string path, ienumerable<int> lineindices) { return file.readlines(path).where((l, i) => lineindices.contains(i)); } public int gettotalrecordcount() { string filename = httpcontext.current.server.mappath("~/app_data/country_revenue.csv"); int count = 0; if (file.exists(filename)) { string[] data = file.readalllines(filename); count= data.length; } return count; } }
default.aspx内容:
<%@ page language="c#" autoeventwireup="true" codebehind="default.aspx.cs" inherits="gridviewbootstrappagination.default" %> <!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title>gridview的bootstrap分页样式</title> <link href="styles/bootstrap.min.css" rel="stylesheet" /> <script src="scripts/jquery-1.8.2.js"></script> <script src="scripts/jquery.bootpag.min.js"></script> <script type="text/javascript"> $(document).ready(function () { // init bootpag var count = gettotalpagecount(); $('#page-selection').bootpag( { total:count }).on("page", function (event, num) { getgriddata(num); }); }); function getgriddata(num) { $.ajax({ type: "post", url: "default.aspx/getrevenuedetail", data: "{ \"pagenumber\":" + num + "}", contenttype: "application/json; charset=utf-8", datatype: "json", success: function (data) { bindgrid(data.d); }, error: function (xhr, status, err) { var err = eval("(" + xhr.responsetext + ")"); alert(err.message); } }); } function bindgrid(data) { $("[id*=gvbspagination] tr").not(":first").not(":last").remove(); var table1 = $('[id*=gvbspagination]'); var firstrow = "$('[id*=gvbspagination] tr:first-child')"; for (var i = 0; i < data.length; i++) { var rownew = $("<tr><td></td><td></td><td></td><td></td></tr>"); rownew.children().eq(0).text(data[i].country); rownew.children().eq(1).text(data[i].revenue); rownew.children().eq(2).text(data[i].salesmanager); rownew.children().eq(3).text(data[i].year); rownew.insertbefore($("[id*=gvbspagination] tr:last-child")); } } function gettotalpagecount() { var mytempvar = 0; $.ajax({ type: "post", url: "default.aspx/gettotalpagecount", data: "", contenttype: "application/json; charset=utf-8", datatype: "json", async:false, success: function (data) { mytempvar=data.d; }, error: function (xhr, status, err) { var err = eval("(" + xhr.responsetext + ")"); alert(err.message); } }); return mytempvar; } </script> </head> <body> <form id="form1" runat="server"> <div style="width:670px;margin-left:auto;margin-right:auto;"> <h2 style="text-align:center;">asp.net gridview的bootstrap分页样式</h2> <asp:gridview id="gvbspagination" runat="server" cssclass="table table-striped table-bordered table-condensed" width="660px" allowpaging="true" pagesize="5" onprerender="gvbspagination_prerender"> <pagertemplate> <div id="page-selection" class="pagination-centered"></div> </pagertemplate> </asp:gridview> <div id="content"></div> </div> </form> </body> </html>
后台代码:
public partial class default : system.web.ui.page { private const int max_records = 5; protected void page_load(object sender, eventargs e) { string filename = server.mappath("~/app_data/country_revenue.csv"); if (!ispostback) { list<revenue> revenue = getrevenuedetail(1); gvbspagination.datasource = revenue; gvbspagination.databind(); } } [webmethod] [scriptmethod(usehttpget = false, responseformat = responseformat.json)] public static list<revenue> getrevenuedetail(int pagenumber) { revenue rv = new revenue(); list<revenue> lstrevenue = rv.getrevenuedetails(pagenumber,max_records); return lstrevenue; } [webmethod] [scriptmethod(usehttpget = false, responseformat = responseformat.json)] public static int gettotalpagecount() { int count=0; revenue rv=new revenue(); count = rv.gettotalrecordcount(); count = count / max_records; return count; } protected void gvbspagination_prerender(object sender, eventargs e) { gridview gv = (gridview)sender; gridviewrow pagerrow = (gridviewrow)gv.bottompagerrow; if (pagerrow != null && pagerrow.visible == false) pagerrow.visible = true; } }
country_revenue.csv
项目运行结果如图:
如果大家还想深入学习,可以点击进行学习,再为大家附3个精彩的专题:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。
上一篇: 使用bash shell删除目录中的特定文件的3种方法
下一篇: Shell中实现飞行文字效果
推荐阅读
-
ASP.NET中GridView 重复表格列合并的实现方法
-
基于GridView和ActivityGroup实现的TAB分页(附源码)
-
利用ASP.NET MVC+Bootstrap搭建个人博客之打造清新分页Helper(三)
-
GridView自定义分页的四种存储过程
-
更改BootStrap popover的默认样式
-
ASP.NET技巧:做个DataList可分页的数据源
-
Android中实现多行、水平滚动的分页的Gridview实例源码
-
asp.net使用FCK编辑器中的分页符实现长文章分页功能
-
ASP.NET技巧:access下的分页方案
-
asp.net GridView中使用RadioButton单选按钮的方法