本文实例为大家分享了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="/UploadFiles/2021-04-02/jquery-1.8.2.js">

后台代码:

 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

ASP.NET GridView的Bootstrap分页样式

项目运行结果如图:

ASP.NET GridView的Bootstrap分页样式

如果大家还想深入学习,可以点击这里进行学习,再为大家附3个精彩的专题:

Bootstrap学习教程

Bootstrap实战教程

Bootstrap插件使用教程

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。

广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。