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 = ...
随机推荐
- Oozie分布式任务的工作流——脚本篇
继前一篇大体上翻译了Email的Action配置,本篇继续看一下Shell的相关配置. Shell Action Shell Action可以执行Shell脚本命令,工作流会等到shell完全执行完毕 ...
- Android-异步任务-AsyncTask
什么是异步任务? 异步任务就是开一个子线程,然后让它去跑,它跑完了就会回来告诉你说,它跑完了,这是结果.这和Java中的回调差不多.我们在OKHttp中很长见到的 onSuccess() 和 onEr ...
- Sql Server系列:运算符和表达式
运算符的一些符号,他们能够用于执行算术运算.字符串连接.赋值以及在字段.常量和变量之间进行比较.在SQL Server 2012中,运算符主要由以下6大类:算术运算符.赋值运算符.比较运算符.逻辑运算 ...
- LINQ系列:LINQ to XML类
LINQ to XML由System.Xml.Linq namespace实现,该namespace包含处理XML时用到的所有类.在使用LINQ to XML时需要添加System.Xml.Linq. ...
- 利用typescript使backbone强类型智能提示
模型类一旦多了没有强类型和智能提示是相当痛苦的,所以. 仅仅用ts定义一个模型类: class Person extends Backbone.Model { defaults = { Name:&q ...
- jQuery 2.0.3 源码分析Sizzle引擎 - 词法解析
声明:本文为原创文章,如需转载,请注明来源并保留原文链接Aaron,谢谢! 浏览器从下载文档到显示页面的过程是个复杂的过程,这里包含了重绘和重排.各家浏览器引擎的工作原理略有差别,但也有一定规则. 简 ...
- Python标准模块--functools
1 模块简介 functools,用于高阶函数:指那些作用于函数或者返回其它函数的函数,通常只要是可以被当做函数调用的对象就是这个模块的目标. 在Python 2.7 中具备如下方法, cmp_to_ ...
- Linux安装Node.js
安装环境:Ubuntu:x86_64 Node.js 官网:https://nodejs.org 下载Node.js: wget https://nodejs.org/dist/v4.4.3/node ...
- jQuery的Internal DSL
JQuery的核心理念是write less,do more(写的更少,做的更多),那么链式方法的设计与这个核心理念不谋而合.那么从深层次考虑这种设计其实就是一种Internal DSL. DSL是指 ...
- Objective-C中的语法糖
写这篇博客源于一个疑问:“WoK~, 这也行?!”.刚接触OC不久,今天做深浅拷贝的测试,无意中把获取NSArray的值写成了用下标获取的方式.当时把注意力放在了深浅拷贝的内存地址分析上了,就没太在意 ...