首页 > 代码库 > 分页查询/组合查询
分页查询/组合查询
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 //每一条数据都是ListItem21 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>]页 5 <asp:LinkButton ID="btn_first" runat="server">首页</asp:LinkButton> 6 <asp:LinkButton ID="btn_prev" runat="server">上一页</asp:LinkButton> 7 <asp:LinkButton ID="btn_next" runat="server">下一页</asp:LinkButton> 8 <asp:LinkButton ID="btn_end" runat="server">末页</asp:LinkButton> 9 <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="true"></asp:DropDownList>10 <asp:Button ID="Button1" runat="server" Text="跳转" />
分页查询/组合查询
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。