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组合查询与分页组合查询结合的更多相关文章

  1. 分页查询和分页缓存查询,List<Map<String, Object>>遍历和Map遍历

    分页查询 String sql = "返回所有符合条件记录的待分页SQL语句"; int start = (page - 1) * limit + 1; int end = pag ...

  2. 013.子查询和分页子查询(sql实例)

    --1 子查询 如果子查询和表连接都实现的时候,推荐用表连接实现( 一般:能用表连接实现的就用表连接,有些情况用表连接不能 或者不易实现的再选择子查询) 系统:缓存,执行计划技术手段 --1 wher ...

  3. linq分页组合查询

    一.linq高级查 1.模糊查(字符串包含) 1 public List<User> Select(string name) 2 { 3 return con.User.Where(r = ...

  4. Webform(Linq高级查、分页、组合查询)

    一.linq高级查 1.模糊查(包含) 1 public List<User> Select(string name) 2 { 3 return con.User.Where(r => ...

  5. LINQ 小项目【组合查询、分页】

    使用 linq 在网页上对用户信息增删改,组合查询,分页显示 using System; using System.Collections.Generic; using System.Linq; us ...

  6. 【2017-06-02】Linq高级查询,实现分页组合查询。

    1.以XXX开头 2.以XXX结尾 3.模糊查询 4.求个数 5.求最大值 6.求最小值 7.求平均值 8.求和 9.升序 10.降序 11.分页 Skip()跳过多少条 Take()取多少条 12. ...

  7. ASP.NETMVC4 分页组合查询解决方法

    本人新手刚在webform转到mvc   像linq  ef啥的,都是不会的不行不行的,不会就问群友,找资料 今天本屌遇到了一个分页组合查询的问题,解决了2个小时,把代码共享给大家 话不多话,直接上代 ...

  8. Web 组合查询加 分页

    使用ADO.NET 数据访问技术制作web端组合查询加分页的功能关键在于查询SQL语句的拼接 以Car 表为例 每页显示3条数据 数据访问类使用查询方法,tsql 查询的连接字符串,查询的参数放到Ha ...

  9. webform:分页组合查询

    一个简单的分页组合查询页面 /// <summary> /// 查询方法 /// </summary> /// <param name="tsql"& ...

随机推荐

  1. JavaScript学习day1

    JavaScript 特点: javascript 是一种脚本语言,它的解释器被称为javascript引擎,JavaScript被发明用于在HTML网页上使用,给HTML 网页增加动态功能 由于ja ...

  2. Python基础之数据基本运算

    一.核心数据类型(五种): 在Python中变量没有数据类型,但关联的对象有数据类型,可通过type函数查看数据类型 1.整型(Int): 包含正整数,负整数和零 二进制:逢二进一,书写格式为 a = ...

  3. 最大流sap

    带当前弧优化 gap优化的sap 甚至省去了开始的bfs分层 虽然花了一些时间了解原理 但是感觉不亏 现在能完全独立靠原理写出具体实现了 #include<cstdio> #include ...

  4. ELK之使用packetbeat分析网络包流量

    介绍 packbeat是一个开源的实时网络抓包与分析框架,内置了很多常见的协议捕获及解析,如HTTP.MySQL.Redis等.在实际使用中,通常和Elasticsearch以及kibana联合使用, ...

  5. css_css 盒子水平居中 垂直居中

    1.盒子垂直居中---常用3种方法 方法2: 2.盒子水平居中 3.垂直水平都居中 之前学过 1.结合上面的知识 2.flex布局可以做到 3.css3  translate  定位

  6. CGI的工作原理

    文章摘自https://blog.csdn.net/nyist327/article/details/41049699 CGI是Web服务器和外部程序之间的一个接口.利用CGI程序可以处理从Web上客 ...

  7. tomcat体系结构

    总体架构解析 Server: 一个StandardServer类实例就表示一个Server容器,TOMCAT启动的时候首先会启动一个Server,一个Server包括多个Service Service ...

  8. subline text3 安装 rem装换工具

    CSSREM 一个CSS的px值转rem值的Sublime Text 3自动完成插件. 插件效果如下: 安装 下载本项目,比如:git clone https://github.com/flashli ...

  9. poj1164

    #include<iostream> using namespace std; ][]; ][]; int roomnum; int maxroom; int m,n; typedef s ...

  10. plsql导入.dmp, .sql步骤

    plsql导入.sql和.dmp文件时,会经常用到,对于初学者来说可能没有那么简单,毕竟oracle数据库比较麻烦. 下面是我自己导入.sql和.dmp文件的步骤. 1.导入.sql文件(sql文件是 ...