ASP. NET GridView's Bootstrap paging style, gridviewbootstrap
The examples in this article share the Bootstrap pagination style of the GridView for your reference. The details are as follows:
Revenue. cs Revenue class, including entity model and business logic
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 content:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "Default. aspx. cs" Inherits = "GridViewBootstrapPagination. Default" %> <! DOCTYPE html>
Background code:
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
Project running result:
If you want to study in depth, you can click here to learn and attach three special topics:
Bootstrap tutorial
Bootstrap tutorial
Bootstrap plugin usage tutorial
The above is all the content of this article. I hope it will be helpful for your learning and support for helping customers.