ASP. NET GridView's Bootstrap paging style, gridviewbootstrap

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.