Linq组合查询与分页组合查询结合
1、组合查询
<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="查询" />
void Button2_Click(object sender, EventArgs e)
{
using (StudentsDataClassesDataContext con = new StudentsDataClassesDataContext())
{
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(); }
}
Repeater1.DataSource = s;
Repeater1.DataBind();
}
}
2、分页+组合查询
<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="Button4" 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;
Button3.Click += Button3_Click;
Button4.Click += Button4_Click;
} void Button4_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();
}
} //把组合查询封装成一个方法
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组合查询与分页组合查询结合的更多相关文章
- 分页查询和分页缓存查询,List<Map<String, Object>>遍历和Map遍历
分页查询 String sql = "返回所有符合条件记录的待分页SQL语句"; int start = (page - 1) * limit + 1; int end = pag ...
- 013.子查询和分页子查询(sql实例)
--1 子查询 如果子查询和表连接都实现的时候,推荐用表连接实现( 一般:能用表连接实现的就用表连接,有些情况用表连接不能 或者不易实现的再选择子查询) 系统:缓存,执行计划技术手段 --1 wher ...
- linq分页组合查询
一.linq高级查 1.模糊查(字符串包含) 1 public List<User> Select(string name) 2 { 3 return con.User.Where(r = ...
- Webform(Linq高级查、分页、组合查询)
一.linq高级查 1.模糊查(包含) 1 public List<User> Select(string name) 2 { 3 return con.User.Where(r => ...
- LINQ 小项目【组合查询、分页】
使用 linq 在网页上对用户信息增删改,组合查询,分页显示 using System; using System.Collections.Generic; using System.Linq; us ...
- 【2017-06-02】Linq高级查询,实现分页组合查询。
1.以XXX开头 2.以XXX结尾 3.模糊查询 4.求个数 5.求最大值 6.求最小值 7.求平均值 8.求和 9.升序 10.降序 11.分页 Skip()跳过多少条 Take()取多少条 12. ...
- ASP.NETMVC4 分页组合查询解决方法
本人新手刚在webform转到mvc 像linq ef啥的,都是不会的不行不行的,不会就问群友,找资料 今天本屌遇到了一个分页组合查询的问题,解决了2个小时,把代码共享给大家 话不多话,直接上代 ...
- Web 组合查询加 分页
使用ADO.NET 数据访问技术制作web端组合查询加分页的功能关键在于查询SQL语句的拼接 以Car 表为例 每页显示3条数据 数据访问类使用查询方法,tsql 查询的连接字符串,查询的参数放到Ha ...
- webform:分页组合查询
一个简单的分页组合查询页面 /// <summary> /// 查询方法 /// </summary> /// <param name="tsql"& ...
随机推荐
- maven与eclipse集成
https://www.cnblogs.com/teach/p/5906425.html
- MVC 程序在编译时提示 GAC与 Temporary ASP.NET Files目录内引用文件版本不一致
今天在调试Mvc程序时,提示GAC与Temporary ASP.NET Files目录内引用文件版本不一致. [A]System.Web.WebPages.Razor.Configuration.Ho ...
- 简单的3d变换
<!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title> ...
- VMware workstation --虚拟机静态ip设置
背景介绍 我在本机win10上安装VMware workstation软件,新建两台centos7虚拟机,最近在配服务,每天虚拟机重启后,ip总会变,服务配置文件又要修改,很麻烦,便需要将其ip由dh ...
- dhtmlx Gantt知识点1
鼠标放在任务上显示信息框: <script src="../../codebase/ext/dhtmlxgantt_tooltip.js?v=5.2.0"></s ...
- 如何设置记事本( .txt文件)的默认编码为UTF-8?
1.在桌面新建一个文本文档,不要写入任何内容,然后手动另存为,将此文档编码改为UTF-8,然后将文件名字改为template.txt: 2.再将template.txt移动到C:\Windows\Sh ...
- 随笔二-https://www.cnblogs.com/shang1680/p/9657994.html
作业要求来自https://edu.cnblogs.com/campus/gzcc/GZCC-16SE2/homework/2097 GitHub远程仓库的地址:https://github.com/ ...
- radio选中与不选中
$("input[name='bankCardType']").val("sdf"); $('input:radio[name="bankCardTy ...
- LeetCode 240 - 搜索二维矩阵 II
编写一个高效的算法来搜索 m x n 矩阵 matrix 中的一个目标值 target.该矩阵具有以下特性: 每行的元素从左到右升序排列.每列的元素从上到下升序排列.示例: 现有矩阵 matrix 如 ...
- [Day22]IO(File、递归)
1.File 1.1 IO概述 (1)当需要把内存中的数据存储到持久化设备上的这个动作称为输出(写)Output操作 (2)当把持久设备上的数据读取到内存中的这个动作称为输入(读)Input操作 1. ...