zoukankan      html  css  js  c++  java
  • Web From 分页

    后台

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    using System.Data;
    
    namespace WebApplication1
    {
        public partial class WebForm1 : System.Web.UI.Page
        {
            SqlConnection conn = new SqlConnection("Data Source=.;Initial Catalog=IOT1706B;Integrated Security=True"); 
            protected void Page_Load(object sender, EventArgs e)
            {
                if (!IsPostBack)
                {
                    BandData();
                }
    
            }
    
            private void BandData(int pageIndex=1,int pageSize=6)
            {
                DataTable dt = new DataTable();
                if (Session["dt"]!=null)
                {
                    dt = Session["dt"] as DataTable;
                }
                else
                {
                    SqlDataAdapter dataAdapter = new SqlDataAdapter("select Id,TiGan,Rsesult from Topic order by Id desc", conn);
                    dataAdapter.Fill(dt);
                    Session["dt"] = dt;
                }
               
                Session["pageIndex"] = pageIndex;
                Session["totalPage"] = dt.Rows.Count / pageSize + (dt.Rows.Count % pageSize > 0 ? 1 : 0);
                var linq = (from s in dt.AsEnumerable()
                            select new
                            {
                                Id = s.Field<int>("Id"),
                                TiGan = s.Field<string>("TiGan"),
                                Rsesult = s.Field<string>("Rsesult"),
                            }).Skip((pageIndex-1)*pageSize).Take(pageSize);
                GridView1.DataSource = linq.ToList();
                GridView1.DataBind();
            }
    
            protected void btnFirst_Click(object sender, EventArgs e)
            {
                BandData();
            }
    
            protected void btnPrev_Click(object sender, EventArgs e)
            {
                int n = (int)Session["pageIndex"] - 1;
                if (n<=0)
                {
                    n = 1;
                }
                BandData(n);
            }
    
            protected void btnNext_Click(object sender, EventArgs e)
            {
                int n = (int)Session["pageIndex"] + 1;
                if (n>= (int)Session["totalPage"])
                {
                   n = (int)Session["totalPage"];
                }
                BandData(n);
            }
    
            protected void btnLast_Click(object sender, EventArgs e)
            {
                int n = (int)Session["totalPage"];
                BandData(n);
            }
        }
    }
  • 相关阅读:
    (原创)C++ 同步队列
    (原创)用C++11的std::async代替线程的创建
    C语言宏应用-------#define STR(X) #X
    c++中数据表如何转成业务实体--map和结构体的相互转换
    线程池的陷阱
    java中map和对象互转工具类的实现示例
    3.python元类编程
    人生苦短,我用python(目录)
    11.多线程、多进程和线程池编程
    10.python3实用编程技巧进阶(五)
  • 原文地址:https://www.cnblogs.com/2018cjx/p/12159934.html
Copyright © 2011-2022 走看看