ajax分页与组合查询配合使用
使用纯HTML页与js、ajax、Linq实现分页与组合查询的配合使用
<body>
<div id="top"><input type="button" id="btn1" class="btn" value="刷新" /></div>
<div style="position:relative;text-align:center;height:50px">
商品名:<input type="text" id="tx1" />
价格<input type="text" id="tx2" />~<input type="text" id="tx3" />
<input type="button" id="btt" value="查询" style="cursor:pointer"/>
</div>
<div style="position:relative;">
<table id="tb1" style="background-color: #00ffff ; text-align: center; width: 100%;">
<thead>
<tr style="color: #ff6a00;">
<td>商品名</td>
<td>图片</td>
<td>数量</td>
<td>尺寸</td>
<td>CPU</td>
<td>价格</td>
<td>操作</td>
</tr>
</thead>
<tbody>
<!--<tr style="background-color: white;">
<td></td>
</tr>-->
</tbody>
</table>
</div>
<div id="ye">
当前第 <span id="nowye"></span> 页  共 <span id="allye"></span> 页
<input id="btn_first" type="button" value="首页" /> <input id="btn_prev" type="button" value="上一页" /> <input type="button" id="btn_next" value="下一页" /> <input type="button" id="btn_end" value="末页" />
<select id="dr1"></select>
</div>
</body>
HTML代码
js与ajax代码:
<script>
var pcount = ;
var Mcount = ;
var aname = "";
var aprice = "";
var bprice ="";
var NowNumber = parseInt($("#nowye").text());
data();
max();
//点击刷新按钮
$("#btn1").click(function () {
data();
})
//上一页
$("#btn_prev").click(function () { NowNumber = parseInt($("#nowye").text()) - ;
if (NowNumber<)
{
return;
}
data();
}
);
//首页
$("#btn_first").click(function () { NowNumber = ;
data();
} );
//末页
$("#btn_end").click(function () { NowNumber = parseInt($("#allye").text());
data();
} );
//快捷跳转
$("#dr1").change(function () {
NowNumber = parseInt($("#dr1").val());
data();
} );
//下一页
$("#btn_next").click(function () { NowNumber = parseInt($("#nowye").text()) + ;
if (NowNumber > parseInt($("#allye").text())) {
return;
}
data();
}
);
//点击查询按钮
$("#btt").click(function () {
aname = $("#tx1").val();
aprice = $("#tx2").val();
bprice = $("#tx3").val();
NowNumber = ;
max();
data();
})
//获取总页数与绑定快捷页数
function max() {
$.ajax({
url: "ajax/allcom.ashx",
data: { "ak": aname, "bk": aprice, "ck": bprice },
type: "post",
dataType: "json",
success: function (data) {
var maxcount = data.cn;
var te = maxcount / (pcount * 1.0);
Mcount = Math.ceil(te);
$("#allye").html(Mcount);
$("#dr1").empty();
for(var i=;i<=Mcount;i++)
{
var str = "<option value=\"" + i + "\">" + i + "</option>";
$("#dr1").append(str);
} },
error: function () {
alert('服务器连接失败!!!');
},
beforeSend: function () { } });
}
//数据展现
function data() {
$.ajax({
url: "ajax/com.ashx",
data: {"un":NowNumber,"yn":pcount,"ak":aname,"bk":aprice,"ck":bprice},
type: "post",
dataType: "json",
success: function (data) {
$("#tb1 tbody").empty();//清空tbody
for (i in data) {
var str = "<tr style=\"background-color: #a9ff98; \" class=\"trs\">";
str += "<td>" + data[i].pname + "</td>";
str += "<td> <img src=\""+ data[i].pic +"\" style=\"width:60px;height:60px\"/> </td>";
str += "<td>" + data[i].pcode + "</td>";
str += "<td>" + data[i].size + "</td>";
str += "<td>" + data[i].cpu + "</td>";
str += "<td>" + data[i].price + "</td>";
str += "<td> <input type=\"button\" class=\"btn2\" value=\"删除\" /> </td>";
str += "</tr>";
$("#tb1 tbody").append(str);
$("#nowye").html(NowNumber);
$("#dr1").val(NowNumber);
}
},
error: function () {
alert('服务器连接失败!!!');
},
beforeSend: function () { } }); };
</script>
public void ProcessRequest(HttpContext context)
{
int pcount = Convert.ToInt32(context.Request["yn"]);
int pagenumber = Convert.ToInt32(context.Request["un"]);
string sname = context.Request["ak"];
int sprice1;
int sprice2;
try
{
sprice1 = Convert.ToInt32(context.Request["bk"]);
}
catch
{
sprice1 = ;
}
try
{
sprice2 = Convert.ToInt32(context.Request["ck"]);
}
catch
{
sprice2 = ;
}
int count = ;
string end = "[";
using (WebDataContext con = new WebDataContext())
{ var clist = con.Computer.AsEnumerable();
if (sname!="")
{
var namelist = con.Computer.Where(r => r.Name.Contains(sname)); clist = clist.Intersect(namelist);
}
if (sprice1 != )
{
var plist = con.Computer.Where(r => Convert.ToInt32(r.price) >= sprice1);
clist = clist.Intersect(plist);
}
if (sprice2 != )
{
var plist2 = con.Computer.Where(r => Convert.ToInt32(r.price) <= sprice2);
clist = clist.Intersect(plist2);
} clist = clist.Skip(pcount * (pagenumber - )).Take(pcount);
foreach (Computer c in clist)
{
//前面有数据
if (count > )
{
end += ",";
}
end += "{\"pname\":\"" + c.Name + "\",\"size\": \"" + c.size + "\",\"cpu\": \"" + c.Cpu + "\",\"price\": \"" + c.price + "\",\"pic\": \"" + c.pic + "\",\"pcode\":\"" + c.pcode + "\",\"pid\":\"" + c.ids + "\" }";
count++;
}
}
end += "]";
context.Response.Write(end);
context.Response.End(); }
com.ashx
public void ProcessRequest (HttpContext context) {
string sname = context.Request["ak"];
int sprice1;
int sprice2;
try
{
sprice1 = Convert.ToInt32(context.Request["bk"]);
}
catch
{
sprice1 = ;
}
try
{
sprice2 = Convert.ToInt32(context.Request["ck"]);
}
catch
{
sprice2 = ;
}
string end="";
using (WebDataContext con = new WebDataContext())
{
var clist = con.Computer.AsEnumerable();
if (sname!="")
{
var namelist = con.Computer.Where(r => r.Name.Contains(sname));
clist = clist.Intersect(namelist);
}
if (sprice1 != )
{
var plist = con.Computer.Where(r => Convert.ToInt32(r.price) >= sprice1);
clist = clist.Intersect(plist);
}
if (sprice2 != )
{
var plist2 = con.Computer.Where(r => Convert.ToInt32(r.price) <= sprice2);
clist = clist.Intersect(plist2);
}
end = "{\"cn\":\"" + clist.Count() + "\"}";
}
context.Response.Write(end);
context.Response.End();
}
allcom.ashx
ajax分页与组合查询配合使用的更多相关文章
- Webform(分页与组合查询配合使用)
1.封装实体类 2.写查询方法 //SubjectData类 public List<Subject> Select(string name) { List<Subject> ...
- Webform(Linq高级查、分页、组合查询)
一.linq高级查 1.模糊查(包含) 1 public List<User> Select(string name) 2 { 3 return con.User.Where(r => ...
- webform 分页、组合查询综合使用
界面: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx ...
- Webform(分页、组合查询)
一.分页 1.写查询方法: public List<Student> Select(int PageCount, int PageNumber) {//PageCount为每页显示条数,P ...
- WebForm 分页与组合查询
1.封装实体类 2.写查询方法 //SubjectData类 public List<Subject> Select(string name) { List<Subject> ...
- Linq的分页与组合查询的配合使用
1.首先使用Linq连接数据库,并扩展属性 public partial class User { public string SexStr { get { string end = "&l ...
- WebForm 分页、组合查询--2017年1月5日
sql = "select * from Commodity"; hs = new Hashtable(); if (txt_name.Text.Trim() != "& ...
- django项目中的ajax分页和条件查询。
1,路由 #主页面路由 re_path('article/article_list/', article.article_list,name='article/article_list/'), #分页 ...
- linq分页组合查询
一.linq高级查 1.模糊查(字符串包含) 1 public List<User> Select(string name) 2 { 3 return con.User.Where(r = ...
随机推荐
- HTTP Status 500 - The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application
j 今天下午一直报这个问题,google了半天没有找到答案.百度了下,说是 tomcat的 lib文件夹下缺少jstl1.2,因为项目里面用的也是 jstl1.2和 standard-1.1.2.ja ...
- 获取Linux主机的CPU、内存、主板、BIOS的信息(Centos)
#!/usr/bin/env python #coding:utf-8 import subprocess import re def Cmd_Exec(cmd): ''' 执行获取信息命令 :par ...
- MyBatis参数绑定规则及原理分析
MyBatis参数的传递有几种不同的方法,本文通过测试用例出发,对其中的方式进行总结和说明,并对其部分源码进行分析. 一.测试用例(环境参考之前博客SSM接口编程一文 http://www.cnblo ...
- Distributed3:SQL Server 创建分布式数据库
分布式数据库的优势是将IO分散在不同的Physical Disk上,每次查询都由多台Server的CPU,I/O共同负载,通过各节点并行处理数据来提高性能,劣势是消耗大量的网络带宽资源,管理难度大.在 ...
- 实战MEF(4):搜索范围
在前面的文章中,几乎每个示例我们都会接触到扩展类的搜索位置,我们也不妨想一下,既然是自动扩展,它肯定会有一个或者多人可供查找的位置,不然MEF框架怎么知道哪里有扩展组件呢? 就像我们用导航系统去查找某 ...
- lintcode 滑动窗口的最大值(双端队列)
题目链接:http://www.lintcode.com/zh-cn/problem/sliding-window-maximum/# 滑动窗口的最大值 给出一个可能包含重复的整数数组,和一个大小为 ...
- Routing 功能概述 - 每天5分钟玩转 OpenStack(98)
路由服务(Routing)提供跨 subnet 互联互通功能. 例如前面我们搭建了实验环境: cirros-vm1 172.16.100.3 vlan100 cirros-vm ...
- Create Volume 操作(Part I) - 每天5分钟玩转 OpenStack(50)
前面已经学习了 Cinder 的架构和相关组件,从本节我们开始详细分析 Cinder 的各种操作,首先讨论 Cinder 如何创建 volume. Create 操作流程如下: 客户(可以是 Open ...
- ES6 - Note4:Class类
1.Class类的介绍 在ES6中新增了Class类的概念,让语法看起来更像是面向对象编程,其实这可以说是一个语法糖,ES5可以做到Class绝大部分功能,但也有一些不同.在ES6以前,可以通过构造函 ...
- 如何高效地向Redis插入大量的数据
最近有个哥们在群里问,有一个日志,里面存的是IP地址(一行一个),如何将这些IP快速导入到Redis中. 我刚开始的建议是Shell+redis客户端. 今天,查看Redis官档,发现文档的首页部分( ...