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 ...
随机推荐
- Android 命令行模拟按键
/***************************************************************************** * Android 命令行模拟按键 * 说 ...
- (二)java环境搭建
Java运行环境的搭建: 什么是JRE,什么是JDK? JRE:(java运行环境)包括jvm(java虚拟机)和java运行的核心类库,如果只是运行java程序,只需安装JRE JDK:(java开 ...
- python学习之面向对象(下)
该篇主要是针对面向对象的细讲,包括类的多重继承,方法的重写,析构函数,回收机制进行讲解 #该类主要是讲述python面象对象的一些特征,包括继承,方法的重写,多态,垃圾回收 class person( ...
- PTA L3-023 计算图 (dfs+数学推导)
“计算图”(computational graph)是现代深度学习系统的基础执行引擎,提供了一种表示任意数学表达式的方法,例如用有向无环图表示的神经网络. 图中的节点表示基本操作或输入变量,边表示节点 ...
- tensorflow中常用激活函数和损失函数
激活函数 各激活函数曲线对比 常用激活函数: tf.sigmoid() tf.tanh() tf.nn.relu() tf.nn.softplus() tf.nn.softmax() tf.nn.dr ...
- bzoj 4565 字符合并
Written with StackEdit. Description 有一个长度为 \(n\) 的 \(01\) 串,你可以每次将相邻的 \(k\) 个字符合并,得到一个新的字符并获得一定分数.得到 ...
- deep Learning 之入门一 (ps:知乎上看到的大佬写的非常好,所以自己记录下)
作者:Jacky Yang 链接:https://www.zhihu.com/question/26006703/answer/129209540 来源:知乎 著作权归作者所有.商业转载请联系作者获得 ...
- 6 字典和集合——《Swift3.0从入门到出家》
字典和集合 字典 字典是集合类型存放多个键值对,其中键是唯一的,不能重复 字典中存放的键值对是无序的,写入的顺序和读取的顺序可能不同 字典中存放的数据是任意类型 字典可以分为可变字典和不可变字典 创建 ...
- 使用 key 登录时分开记录操作历史记录
线上服务器一般都是配置 key 登录,一个账号可以多个工作人员连接,操作命令历史却全部记录在一个文件中,当然后查看某条命令是谁执行的时候就不好查了.这时候我们就可以通过配置 histroy 相关环境变 ...
- (转)Android代码混淆-添加了Gson遇到的问题
折腾了好久.....郁闷 -_- 1.首先,project.properties里的配置文件变了,之前的项目一直都是在project.properties这个文件中添加一行proguard.confi ...