• 分页查询/组合查询


     1 </组合查询
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    
    public partial class Default2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Repeater1.DataSource = new CarData().Select("select *from Car", new Hashtable());
                Repeater1.DataBind();
            }
    
            Button2.Click += Button2_Click;
        }
    
        void Button2_Click(object sender, EventArgs e)
        {
            Hashtable hs = new Hashtable();//哈希表集合,自定义
    
            int count = 0;//中间变量
    
            string Tsql = "select *from car";//默认查全部
    
            if (TextBox1.Text != "")
            {
                Tsql += " where name like @a";//防攻击
                hs.Add("@a", "%" + TextBox1.Text + "%");
                count++;
            }
    
            if (TextBox2.Text != "")
            {
                if (count > 0)
                {
                    Tsql += " and oil=@b";
                }
                else
                {
                    Tsql += " where oil=@b";
                }
                count++;
                hs.Add("@b", TextBox2.Text);
            }
    
            if (TextBox3.Text != "")
            {
                if (count > 0)
                {
                    Tsql += " and powers = @c";
                }
                else
                {
                    Tsql += " where powers = @c";
                }
                hs.Add("@c", TextBox3.Text);
            }
    
            Label3.Text = Tsql;
    
            Repeater1.DataSource = new CarData().Select(Tsql, hs);
            Repeater1.DataBind();
           // select *from car where name like "%"+ + "%" "and oil=" + + "and powers=" + +;
        }
    }
     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Web;
     5 using System.Web.UI;
     6 using System.Web.UI.WebControls;
     7 
     8 public partial class fenye : System.Web.UI.Page
     9 {
    10     protected void Page_Load(object sender, EventArgs e)
    11     {
    12         if (!IsPostBack)
    13         {
    14             Repeater1.DataSource = new ChainDA().Select(Pagcount, 1);//默认是5条数据,第一页
    15             Repeater1.DataBind();
    16             Label1.Text = "1";//打开就显示当前第1页
    17 
    18             for (int i = 1; i <= Max(); i++)
    19             { 
    20             //每一条数据都是ListItem
    21                 ListItem li = new ListItem(i.ToString(),i.ToString());
    22                 //复合控件
    23                 DropDownList1.Items.Add(li);
    24             }
    25 
    26 
    27         }
    28         Label2.Text = Max().ToString();//显示总共多少页
    29 
    30         btn_first.Click += btn_first_Click;//首页按钮
    31         btn_end.Click += btn_end_Click;//末页按钮
    32         btn_prev.Click += btn_prev_Click;//上一页按钮
    33         btn_next.Click += btn_next_Click;//下一页按钮
    34         Button1.Click += Button1_Click;//点击跳转按钮
    35         DropDownList1.SelectedIndexChanged += Button1_Click;
    36     }
    37 
    38     void Button1_Click(object sender, EventArgs e)
    39     {//跳转按钮
    40         int a = Convert.ToInt32(DropDownList1.SelectedItem.Text);
    41         Label1.Text = a.ToString();
    42         Repeater1.DataSource = new ChainDA().Select(Pagcount, a);
    43         Repeater1.DataBind();//重新赋值
    44     }
    45     int Pagcount = 10;//每页显示多少条
    46    
    47     //下一页按钮
    48     void btn_next_Click(object sender, EventArgs e)
    49     {
    50         int num = Convert.ToInt32(Label1.Text);//
    51         num++;//下一页
    52         if (num >= Max())//超过最大页就不执行了,下面语句也不执行
    53         {
    54             return;
    55         }
    56         Label1.Text = num.ToString();
    57         Repeater1.DataSource = new ChainDA().Select(Pagcount, num);//显示Pagcount条数据,num是下一页
    58         Repeater1.DataBind();//重新赋值
    59     }
    60     //上一页按钮
    61     void btn_prev_Click(object sender, EventArgs e)
    62     {
    63         int num = Convert.ToInt32(Label1.Text);//
    64         num--;//上一页
    65         if (num < 1)//超过最小页就不执行了,下面语句也不执行
    66         {
    67             return;
    68         }
    69         Label1.Text = num.ToString();
    70         Repeater1.DataSource = new ChainDA().Select(Pagcount, num);//显示Pagcount条数据,num是上一页
    71         Repeater1.DataBind();//重新赋值
    72     }
    73     //末页按钮
    74     void btn_end_Click(object sender, EventArgs e)
    75     {
    76         Repeater1.DataSource = new ChainDA().Select(Pagcount, Max());//显示Pagcount条数据,Max()是最大页
    77         Repeater1.DataBind();//重新赋值
    78         Label1.Text = Max().ToString();
    79     }
    80     //首页按钮
    81     void btn_first_Click(object sender, EventArgs e)
    82     {
    83 
    84         Repeater1.DataSource = new ChainDA().Select(Pagcount, 1);//显示Pagcount条数据,1是首页
    85         Repeater1.DataBind();//重新赋值
    86         Label1.Text ="1";
    87     }
    88     private int Max()//最大页
    89     {
    90         int count = new ChainDA().Select().Count;
    91         double aa= count/(Pagcount*1.0);//所有的数据除以每页显示的条数就是一共多少页
    92         return Convert.ToInt32(Math.Ceiling(aa));//返回最大或等于的整数
    93     }
    94 }
    asp:Repeater>
     2         <br />
     3         当前第[<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>]页,
     4         共[<asp:Label ID="Label2" runat="server" Text="Label"></asp:Label>]页 &nbsp;
     5         <asp:LinkButton ID="btn_first" runat="server">首页</asp:LinkButton>&nbsp;
     6         <asp:LinkButton ID="btn_prev" runat="server">上一页</asp:LinkButton>&nbsp;
     7         <asp:LinkButton ID="btn_next" runat="server">下一页</asp:LinkButton>&nbsp;
     8         <asp:LinkButton ID="btn_end" runat="server">末页</asp:LinkButton>&nbsp;
     9         <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"></asp:DropDownList>
    10         <asp:Button ID="Button1" runat="server" Text="跳转" />
  • 相关阅读:
    java初学者之java语言主要知识点三
    C++类的对象和类的指针的区别
    win32多线程: 线程创建与结束等待
    多线程学习:win32多线程编程基本概念(转)
    C++常用数据类型和Windows常见数据类型
    VC++2017关于项目出现"const char *" 类型的实参与 "char *" 类型的形参不兼容错误的解决方法
    Linux环境下vi/vim编辑器常用命令
    c++学习笔记之类模板
    c++学习笔记之函数重载和模板理解
    c++学习笔记之多态和虚函数
  • 原文地址:https://www.cnblogs.com/weiwenxin01/p/5950532.html
Copyright © 2020-2023  润新知