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. PHP定界符<<<EOF

    PHP定界符<<<EOF 一.为什么需要使用定界符: 因为在编程过程中难免会遇到用echo来输出大段的html和javascript脚本的情况, 如果用传统的输出方法 ——按字符串输 ...

  2. Java 多线程 sleep()方法与yield()方法的区别

    sleep()方法与yield()方法的区别如下: 1 是否考虑线程的优先级不同 sleep()方法给其他线程运行机会时不考虑线程的优先级,也就是说,它会给低优先级的线程运行的机会.而yield()方 ...

  3. (84)Wangdao.com第十八天_JavaScript Promise 对象

    Promise 对象 是 JavaScript 的异步操作解决方案,为异步操作提供统一接口. 目前 JavaScript 原生支持 Promise 对象 它起到代理作用(proxy),充当异步操作与回 ...

  4. Node.js_简介及其 npm 包管理器基本使用_npm_cnpm_yarn_cyarn

    Node.js 既是语言也是平台,跳过了 Apache.Nginx 等 HTTP 服务器,直接面向前端开发 JavaScript 是由 ECMAScript.文档对象模型(DOM)和浏览器对象模型(B ...

  5. pheatmap, gplots heatmap.2和ggplot2 geom_tile实现数据聚类和热图plot

    主要步骤 pheatmap 数据处理成矩阵形式,给行名列名 用pheatmap画热图(pheatmap函数内部用hclustfun 进行聚类) ggplot2 数据处理成矩阵形式,给行名列名 hclu ...

  6. DEV中右键菜单如何只在非空单元格上显示?

    问题: 1. 开发时,我的winform程序中有很多gridview,我希望右键菜单只在我点击非空的行时才显示,点击其他空白区域时不显示: 2. 有一个树状导航图,treelist 中的节点都有右键菜 ...

  7. python之str字符串

    字符串是python非常重要的数据类型,它是一个序列(列表和元组也是序列),有下标,可以通过下标遍历字符串序列:同时字符串也是一个不可变数据类型,每次使用"+"拼接字符串时都会产生 ...

  8. Python003-测试辅助示例应用数据库更新语句创建

    上周同事又问一个问题:表 C_Application 中数据量较大,需要批量更新 load_start_time 的时间为 '1900-01-01 18:43:49' 为初始值,以一定时间间隔且每次更 ...

  9. iOS 反调试

    反调试主要分为两种,第一种阻止调试器附加,第二种是检测是否有调试器存在 1.ptrace是系统用来对运行中的进程进行调试和跟踪的工具,通过ptrace,可以对另一个进程实现调试跟踪.但是里面提供了一个 ...

  10. AWS deepracer

    0.安装 坑很多,Ubuntu16.04上安python3,gazebo9,各种包,最后在python2下roslaunch,参见我爱豆的github: https://github.com/exit ...