【2017-06-02】Linq高级查询,实现分页组合查询。
1、以XXX开头
2、以XXX结尾
3、模糊查询
4、求个数
5、求最大值
6、求最小值
7、求平均值
8、求和
9、升序
10、降序
11、分页
Skip()跳过多少条
Take()取多少条
12、分页组合查询
界面部分
<form id="form1" runat="server">
<div>
车名:<asp:TextBox ID="txt_carname" runat="server"></asp:TextBox>
油耗:<asp:DropDownList ID="dr_oil" runat="server">
<asp:ListItem Text="大于" Value=">"></asp:ListItem>
<asp:ListItem Text="小于" Value="<"></asp:ListItem>
<asp:ListItem Text="等于" Value="="></asp:ListItem>
<asp:ListItem Text="大于等于" Value=">="></asp:ListItem>
<asp:ListItem Text="大于等于" Value=">="></asp:ListItem>
</asp:DropDownList>
<asp:TextBox ID="txt_oil" runat="server"></asp:TextBox>
价格:<asp:DropDownList ID="dr_price" runat="server">
<asp:ListItem Text="全部" Value="null"></asp:ListItem>
<asp:ListItem Text="小于30万" Value=""></asp:ListItem>
<asp:ListItem Text="30-40万" Value=""></asp:ListItem>
<asp:ListItem Text="40-50万" Value=""></asp:ListItem>
<asp:ListItem Text="大于50万" Value=""></asp:ListItem> </asp:DropDownList> <asp:Button ID="Button1" runat="server" Text="查询" />
<table style="width: 100%; background-color: navy; text-align: center">
<tr style="height: 40px; color: white;">
<td>id</td>
<td>编号</td>
<td>车名</td>
<td>油耗</td>
<td>马力</td>
<td>价格</td>
</tr>
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<tr style="background-color: white;">
<td><%#Eval("ids") %></td>
<td><%#Eval("code") %></td>
<td><%#Eval("name") %></td>
<td><%#Eval("oil") %></td>
<td><%#Eval("powers") %></td>
<td><%#Eval("price") %></td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
当前第【 <asp:Label ID="lab_nownumber" runat="server" Text=""></asp:Label> 】页,一共【 <asp:Label ID="lab_maxnumber" runat="server" Text=""></asp:Label> 】页。
<asp:Button ID="btn_first" runat="server" Text="首页" /><asp:Button ID="btn_prev" runat="server" Text="上一页" /><asp:Button ID="btn_next" runat="server" Text="下一页" /><asp:Button ID="btn_last" runat="server" Text="尾页" />
</div>
</form>
后台代码
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class Main : System.Web.UI.Page
{
int PageCount = ;
protected void Page_Load(object sender, EventArgs e)
{
Button1.Click += Button1_Click;
btn_first.Click += btn_first_Click;
btn_next.Click += btn_next_Click;
btn_prev.Click += btn_prev_Click;
btn_last.Click += btn_last_Click;
if (!IsPostBack)
{
using (Data0216DataClassesDataContext con = new Data0216DataClassesDataContext())
{
Repeater1.DataSource = Data().Skip().Take(PageCount);
Repeater1.DataBind();
lab_maxnumber.Text = Max().ToString();
}
}
} void btn_last_Click(object sender, EventArgs e)
{
Repeater1.DataSource = Data().Skip((Max() - ) * PageCount);
Repeater1.DataBind();
lab_nownumber.Text = Max().ToString();
lab_maxnumber.Text = Max().ToString();
} void btn_prev_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(lab_nownumber.Text) - ;
if (a > )
{
Repeater1.DataSource = Data().Skip((a - ) * PageCount).Take(PageCount);
Repeater1.DataBind();
lab_nownumber.Text = a.ToString();
lab_maxnumber.Text = Max().ToString();
}
} void btn_next_Click(object sender, EventArgs e)
{
int a = Convert.ToInt32(lab_nownumber.Text) + ;
if (a <= Max())
{
Repeater1.DataSource = Data().Skip((a - ) * PageCount).Take(PageCount);
Repeater1.DataBind();
lab_nownumber.Text = a.ToString();
lab_maxnumber.Text = Max().ToString();
}
} void btn_first_Click(object sender, EventArgs e)
{
Repeater1.DataSource = Data().Skip().Take(PageCount);
Repeater1.DataBind();
lab_nownumber.Text = "";
lab_maxnumber.Text = Max().ToString();
} void Button1_Click(object sender, EventArgs e)
{
Repeater1.DataSource = Data().Skip().Take(PageCount);
Repeater1.DataBind();
lab_nownumber.Text = "";
lab_maxnumber.Text = Max().ToString();
} public List<car> Data()
{ using (Data0216DataClassesDataContext con = new Data0216DataClassesDataContext())
{
List<car> clist = con.car.ToList(); if (txt_carname.Text.Trim().Length > )
{
clist = clist.Where(r => r.name.Contains(txt_carname.Text.Trim())).ToList();
} if (txt_oil.Text.Trim().Length > )
{
if (dr_oil.SelectedValue == ">")
clist = clist.Where(r => r.oil > Convert.ToDecimal(txt_oil.Text)).ToList();
if (dr_oil.SelectedValue == "<")
clist = clist.Where(r => r.oil < Convert.ToDecimal(txt_oil.Text)).ToList();
if (dr_oil.SelectedValue == ">=")
clist = clist.Where(r => r.oil >= Convert.ToDecimal(txt_oil.Text)).ToList();
if (dr_oil.SelectedValue == "<=")
clist = clist.Where(r => r.oil <= Convert.ToDecimal(txt_oil.Text)).ToList();
if (dr_oil.SelectedValue == "=")
clist = clist.Where(r => r.oil == Convert.ToDecimal(txt_oil.Text)).ToList();
} if (dr_price.SelectedValue != "null")
{
if (dr_price.SelectedValue == "")
clist = clist.Where(r => r.price < ).ToList();
if (dr_price.SelectedValue == "")
clist = clist.Where(r => r.price >= && r.price < ).ToList();
if (dr_price.SelectedValue == "")
clist = clist.Where(r => r.price >= && r.price < ).ToList();
if (dr_price.SelectedValue == "")
clist = clist.Where(r => r.price >= ).ToList();
}
return clist;
}
}
public int Max()
{
return Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(Data().Count) / PageCount));
}
}
【2017-06-02】Linq高级查询,实现分页组合查询。的更多相关文章
- Linq组合查询与分页组合查询结合
1.组合查询 <div>姓名:<asp:TextBox ID="T1" runat="server"></asp:TextBox& ...
- ASP.NETMVC4 分页组合查询解决方法
本人新手刚在webform转到mvc 像linq ef啥的,都是不会的不行不行的,不会就问群友,找资料 今天本屌遇到了一个分页组合查询的问题,解决了2个小时,把代码共享给大家 话不多话,直接上代 ...
- webform:分页组合查询
一个简单的分页组合查询页面 /// <summary> /// 查询方法 /// </summary> /// <param name="tsql"& ...
- Webform(Linq高级查、分页、组合查询)
一.linq高级查 1.模糊查(包含) 1 public List<User> Select(string name) 2 { 3 return con.User.Where(r => ...
- linq分页组合查询
一.linq高级查 1.模糊查(字符串包含) 1 public List<User> Select(string name) 2 { 3 return con.User.Where(r = ...
- Webform--LinQ 分页组合查询
一.linq高级查 1.模糊查(字符串包含) public List<User> Select(string name) { return con.User.Where(r => r ...
- ASP.NET 分页+组合查询 练习
分页和组合查询都是通过拼接SQL语句到数据库查询进行实现 到汽车表(car)中查询 ,汽车表选取了“编号 code”,“车名 name”,“日期 time”,“油耗 oil ”,“马力 powers” ...
- 分页查询和分页缓存查询,List<Map<String, Object>>遍历和Map遍历
分页查询 String sql = "返回所有符合条件记录的待分页SQL语句"; int start = (page - 1) * limit + 1; int end = pag ...
- 013.子查询和分页子查询(sql实例)
--1 子查询 如果子查询和表连接都实现的时候,推荐用表连接实现( 一般:能用表连接实现的就用表连接,有些情况用表连接不能 或者不易实现的再选择子查询) 系统:缓存,执行计划技术手段 --1 wher ...
随机推荐
- 如果使用 Python3(Flask) 一步一步模拟一个网页微信客户端
目录 Web Weixin Pipeline 一.获取登录的二维码 1.1.打开浏览器输入下面网址 1.2.梳理原理 1.3.代码实现 1.4.启动测试 二.扫码成功 2.1.扫码状态 2.2.原理状 ...
- 常用CSS媒体查询
@media screen and (orientation: portrait) { /*竖屏 css*/} @media screen and (orientation: landscape) { ...
- linux /etc/profile bashrc bash_profile
文件: /etc/profile ~/.bashrc 和 ~/.bash_profile 的使用区别: /etc/profile: 全局 环境变量等,在机器重启后执行一次, 用于设置环境变量,更 ...
- RMQ问题--ST
#include<iostream> #include<cstdio> #include<cmath> using namespace std; ; ]; int ...
- Centos7服务器环境搭建
1.Apache安装 yum install httpd systemctl start httpd.service #启动 systemctl stop httpd.service#停止 syste ...
- jdbc配置及使用测试
源码:https://github.com/xiaostudy/jdbc_test1 这是没有使用连接池的 目录 创建的sql语句create.sql DROP TABLE IF EXISTS t_u ...
- 洛谷 题解 P1284 【三角形牧场】
状态: dp[i][j]表示用i和j的木板能否搭成,不用去管第三块,因为知道了两块的长度与周长,那就可以表示出第三块:c-i-j 转移 有点类似于背包 if((j-l[i]>=0&&am ...
- SQL Server 学习之环境搭建
SQL Server 环境搭建 说明:本文是sqlServer的安装和测试环境的搭建 版本是SQLServer 2005版,由于该版本只能在Windows7或者更低的系统上才能安装,更高的系统请安装S ...
- SQLite进阶-17.视图
目录 视图(View) 操作视图 更新视图 删除视图 查看所有的视图 视图(View) 视图是一个预定义的SQLite查询的形式存在的表的组合. 可以包含一个表的所有行或从一个或多个表选定行.可以从一 ...
- LeetCode 第 15 场双周赛
1287.有序数组中出现次数超过25%的元素 1288.删除被覆盖区间 1286.字母组合迭代器 1289.下降路径最小和 II 下降和不能只保留原数组中最小的两个,hacked. 1287.有序数组 ...