zoukankan      html  css  js  c++  java
  • 多条件查询与上下翻页

    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"]);   

          }   

      }

    }

  • 相关阅读:
    在模拟器安装测试APP,给指定设备安装APP
    设置安卓模拟器,打开模拟器,设置语言为中文
    使用appium1.4在android8.0真机上测试程序时报错command failed shell "ps 'uiautomator'"的解决方式
    appium1.4+华为8.0执行自动化脚本,报启动session失败,原因是unicode_ime_apk\Uni codeIMEdebug.apk在手机上已存在,再次安装失败,导致启动session失败,解决办法:换高版本的appium
    搭建appium+maven手机自动化测试环境搭建
    appium1.7的使用
    SDK打开模拟器遇到SDK包里缺少API组件,附上我的解决历程,心累
    简单记录下Jmeter通过CSV保存测试数据,测试用例,及将测试结果导出到Excel里
    基于webpack的React项目搭建(一)
    基于webpack的React项目搭建(二)
  • 原文地址:https://www.cnblogs.com/hansonglin/p/4877429.html
Copyright © 2011-2022 走看看