• 多条件查询与上下翻页


    using System; using System.Collections.Generic;

    using System.Linq; using System.Web;

    using System.Web.UI; using System.Web.UI.WebControls;

    public partial class _Default : System.Web.UI.Page

    {    

    protected void Page_Load(object sender, EventArgs e)    

    {       //绑定显示数据

      if (!IsPostBack)        

    {            

    TestDataContext context = new TestDataContext();

                Repeater1.DataSource = context.Car;           

      Repeater1.DataBind();       

      }    

    }    

    protected void btnSelect_Click(object sender, EventArgs e)   

      {    // 双击查询按钮

        TestDataContext context = new TestDataContext();

            List<Car> list = context.Car.ToList();

            //判断第一个条件      

       string key = txtName.Text;      

       if (key != "")        

    {         

        list = list.Where(p=>p.Name.Contains(key)).ToList();

                //使关键字变色          

       foreach (Car data in list)        

         {          

           string s = data.Name.Replace(key, "<mark>" + key + "</mark>");

                    data.Name = s;          

       }   

          }

            //判断第二个条件         

           string mi = txtJGmin.Text;   

          string ma = txtJGmax.Text;

            if (mi != "" && ma != "")       

      {        

         decimal min = Convert.ToDecimal(txtJGmin.Text);       

          decimal max = Convert.ToDecimal(txtJGmax.Text);         

        list = list.Where(p=>p.Price.Value>=min && p.Price.Value<=max).ToList();       

      }

            //指定数据源      

       Repeater1.DataSource = list;       

      Repeater1.DataBind();

        }

    上下翻页:

        private int zys = 0;   

      private int n = 1;    

    protected void Page_Load(object sender, EventArgs e)   

      {              

           if (!IsPostBack)      

       {           

      Session["n"] = 1;      

           showye(n);       

      }    

    }    

    public string showdatetime()   

      {       

      return Convert.ToDateTime(Eval("Time")).ToString("yyyy年MM余额dd日");    

    }    

    public void filltxt()   

      {  

           DataClassesDataContext context = new DataClassesDataContext();    

         int a = context.Car.Count();    

         if (a % 5 == 0)       

      {          

       zys = a / 5;    

         }     

        else       

      {         

        zys = a / 5 + 1;  

           }    

    }   

      protected void Button1_Click(object sender, EventArgs e)    

    {       //上翻页

      if (n <= 1)       

    {           

      Literal1.Text = "<script type='text/javascript'>alert('已经是第一页了')<script>";       

      }      

       else       

      {         

        Session["n"] = n - 1;       

          showye(n - 1);               

    }    

    }     

      public void showye(int x)   

      {        

    DataClassesDataContext context = new DataClassesDataContext();      

       Repeater1.DataSource = context.Car.Skip((x - 1) * 5).Take(5);    

         Repeater1.DataBind();         Label1.Text = "当前第:" + x + "页";    

    }    

    protected void Button2_Click(object sender, EventArgs e)   //往下翻页

      {      

       if (n >= zys)   //判断是否大于总页数

          {          

       Literal1.Text = "<script type='text/javascript'>alert('已经是最后一页了')</script>";       

      }     

        else    

         {        

         Session["n"] = n + 1;        

         showye(n + 1);        

         Literal1.Text = "";       

      }  

       }  

       protected void Button3_Click(object sender, EventArgs e)  

       {      

       int a = Convert.ToInt32(TextBox1.Text);    

         if (a > 1 && a <= zys)     

        {            

    Session["n"] = a;       

          showye(a);        

         Literal1.Text = "";    

         }        

    else       

      {     

        Literal1.Text="<script type='text/javascript'>alert('页数超出范围')</script>";        

    }    

         filltxt();     

        if (Session["n"] != null)      

       {       

          n = Convert.ToInt32(Session["n"]);   

          }   

      }

    }

  • 相关阅读:
    ffmpeg命令行获取RTSP流并每秒截取一张解码存储为jpg
    快速排序
    ffmpeg参数中文详细解释
    Docker
    elasticsearch的安装和配置
    C 语言-运算符(算术运算符,类型转换,赋值运算符,自增,自减,sizeof 运算符,逗号运算符,关系运算符,逻辑运算符,三目运算符)
    c语言-printf函数和scanf函数简单使用
    将JPA通用的实现方法封装成一个抽象类进行拓展
    工具类里的静态变量如何获取application.yml或者application.properties里的属性
    记java实体类属性名为全部为大写踩的坑(基础)
  • 原文地址:https://www.cnblogs.com/hansonglin/p/4877429.html
Copyright © 2020-2023  润新知