linq 条件查询与分页
<div>姓名:<asp:TextBox ID="T1" runat="server"></asp:TextBox></div>
<div>
性别:<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Text="男和女" Value="Null"></asp:ListItem>
<asp:ListItem Text="男" Value="True"></asp:ListItem>
<asp:ListItem Text="女" Value="False"></asp:ListItem>
</asp:DropDownList>
</div>
<div>
成绩:<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem Text="不限" Value="Null"></asp:ListItem>
<asp:ListItem Text="大于" Value=">"></asp:ListItem>
<asp:ListItem Text="小于" Value="<"></asp:ListItem>
</asp:DropDownList><asp:TextBox ID="T2" runat="server"></asp:TextBox>
</div>
<asp:Button ID="Button2" runat="server" Text="查询" /><br />
当前页数:<asp:Label ID="L2" runat="server" Text=""></asp:Label>
总页数:<asp:Label ID="L3" runat="server" Text=""></asp:Label><br />
<asp:Button ID="Button3" runat="server" Text="上一页" /><asp:Button ID="Button6" runat="server" Text="下一页" />
int Pcount = ;
protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack)
{//绑定数据,跳过0条,取2条
using (StudentsDataClassesDataContext con = new StudentsDataClassesDataContext())
{
Repeater1.DataSource = SS(con).Take(Pcount);
Repeater1.DataBind();
L3.Text = MaxP().ToString();
}
//Repeater1.DataSource = con.Stu.ToList();
//Repeater1.DataBind();
} Button1.Click += Button1_Click;
Button2.Click += Button2_Click;
//Button4.Click += Button4_Click;
//Button5.Click += Button5_Click;
Button3.Click += Button3_Click;
Button6.Click += Button6_Click;
} void Button6_Click(object sender, EventArgs e)
{
using (StudentsDataClassesDataContext con = new StudentsDataClassesDataContext())
{
int a = Convert.ToInt32(L2.Text) + ;
if (a > Convert.ToInt32(MaxP()))
{ return; }
Repeater1.DataSource = SS(con).Skip((a - ) * Pcount).Take(Pcount);
Repeater1.DataBind();
L2.Text = a.ToString(); }
} void Button3_Click(object sender, EventArgs e)
{
using (StudentsDataClassesDataContext con = new StudentsDataClassesDataContext())
{
int a = Convert.ToInt32(L2.Text) - ;
if (a < )
{ return; }
Repeater1.DataSource = SS(con).Skip((a - ) * Pcount).Take(Pcount);
Repeater1.DataBind();
L2.Text = a.ToString();
}
} void Button2_Click(object sender, EventArgs e)
{
using (StudentsDataClassesDataContext con = new StudentsDataClassesDataContext())
{
Repeater1.DataSource = SS(con).Take(Pcount);
Repeater1.DataBind();
L2.Text = "";
L3.Text = MaxP().ToString();
}
} //void Button5_Click(object sender, EventArgs e)
//{
// Response.Redirect("toupiao.aspx");
//} //void Button4_Click(object sender, EventArgs e)
//{
// Response.Cookies["id2"].Expires = DateTime.Now.AddDays(-10);
//}
//添加
void Button1_Click(object sender, EventArgs e)
{
Response.Redirect("Add.aspx");
}
//把组合查询封装成一个方法
public List<Stu> SS(StudentsDataClassesDataContext con)
{
List<Stu> s = con.Stu.ToList(); if (T1.Text.Trim().Length > )
{ s = s.Where(r => r.Name.Contains(T1.Text.Trim())).ToList(); }
if (DropDownList1.SelectedValue != "Null")
{
s = s.Where(r => r.Sex == Convert.ToBoolean(DropDownList1.SelectedValue)).ToList();
}
if (DropDownList2.SelectedValue != "Null")
{
if (DropDownList2.SelectedValue == ">")
{ s = s.Where(r => r.Score > Convert.ToInt32((T2.Text.Trim()))).ToList(); }
else
{ s = s.Where(r => r.Score < Convert.ToInt32((T2.Text.Trim()))).ToList(); }
}
return s;
}
////获取最大页数
public int MaxP()
{
using (StudentsDataClassesDataContext con = new StudentsDataClassesDataContext())
{
return Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(SS(con).Count) / Pcount));
}
}
linq 条件查询与分页的更多相关文章
- SSM整合 mybatis多条件查询与分页
多条件查询与分页: 通过页面的houseName.floorage获取值传到前端视图(HouseSearchVO)实体类中的houseName,floorage建立houseSearchVO对象. 通 ...
- WebFrom 小程序【条件查询与分页整合】
将前面的条件查询功能与分页显示整合到一个页面中 <%@ Page Language="C#" AutoEventWireup="true" CodeFil ...
- Linq高级查询,分页查询及查询分页结合
一.高级查询与分页查询 1.以...开头 StartsWith Repeater1.DataSource=con.Users.Where(r=>r.Nickname.StartsWith( ...
- TP条件查询和分页查询
一.条件查询 前端页面 <!doctype html> <html> <head> <meta charset="utf-8"> & ...
- Spring MVC和Spring Data JPA之按条件查询和分页(kkpaper分页组件)
推荐视频:尚硅谷Spring Data JPA视频教程,一学就会,百度一下就有, 后台代码:在DAO层继承Spring Data JPA的PagingAndSortingRepository接口实现的 ...
- spring data jpa实现多条件查询(分页和不分页)
目前的spring data jpa已经帮我们干了CRUD的大部分活了,但如果有些活它干不了(CrudRepository接口中没定义),那么只能由我们自己干了.这里要说的就是在它的框架里,如何实现自 ...
- PHP连接数据库实现多条件查询与分页功能——关于租房页面的完整实例操作
租房页面如图: 代码如下: <!DOCTYPE html><html> <head> <meta charset="UTF-8& ...
- (转)Entity Framework4.1实现动态多条件查询、分页和排序
原文:http://www.cnblogs.com/ahui/archive/2011/08/04/2127282.html EF通用的分页实现: 1 2 3 4 5 6 7 8 9 10 11 12 ...
- 【spring data jpa】带有条件的查询后分页和不带条件查询后分页实现
一.不带有动态条件的查询 分页的实现 实例代码: controller:返回的是Page<>对象 @Controller @RequestMapping(value = "/eg ...
随机推荐
- nodejs express project
user root install express npm install express -g install express... npm install express-generator -g ...
- 【学习】JennyHui学英语 - 生词积累
(主要是来自于普特英语) 平常积累 20140820 20140826 VOA慢速英语生词积累 2014-10-08 2014-10-11 2014-10-13 2014-10-14 2014-10- ...
- Oracle回收站 使用
查询回收站 SELECT * FROM RECYCLEBIN; SELECT * FROM USER_RECYCLEBIN; --USER_RECYCLEBING与RECYCLEBIN是同义词,字段完 ...
- 使用wlan接收器经常重新登录怎么办
wlan接收器是一个大功率的网卡,能够接受耿远距离的无线网络,在农村和乡镇很普及,很多家庭里都是用这个装置来接受远距离的CMCC信号.但是在使用的时候会经常出现一些问题,例如我们登陆以后,还没等上网就 ...
- 剑指offer-第四章解决面试题的思路(包含min函数的栈)
题目:定义栈的数据结构,请在该类型中实现一个能够得到栈的最小元素的min函数,在该栈中,调用min,push及pop的时间复杂度都是O(1) 思路:定义两个栈分别为dataStack和minStack ...
- [Err] 1067 - Invalid default value for 'xxxTime'
下面是导入sql脚本的的局部脚本 `xxxTime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', 发现是NO_ZERO_IN_DATE,NO_Z ...
- 解决使用Qt creator时出现Cannot overwrite file ..Permission denied
前两天在linux下使用Qt creator, 切换到了管理员使用了Qt creator后,再切换为普通用户,发现出现了 Cannot overwrite file ..Permission deni ...
- PyYAML和configparser模块讲解
Python也可以很容易的处理ymal文档格式,只不过需要安装一个模块,参考文档:http://pyyaml.org/wiki/PyYAMLDocumentation ymal主要用于配置文件. Co ...
- php中的continue用法
continue 2 表示跳出两层 continue 默认跳出一层 if (count($content_arr) > 0 ) { // 获取相应的goods数据 $goodsdata = ar ...
- 混搭下的C与C++内存操作
源自最近遇到一个的问题,先介绍一下背景.项目中混用了C与C++编程范式,鉴于项目成员背景不一,每个模块的负责人可以自行2选1.同时为了提高效率,C范式的模块被允许使用STL库的部分容器(其实也就仅仅大 ...