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 = ...
随机推荐
- jQuery 2.0.3 源码分析core - 整体架构
拜读一个开源框架,最想学到的就是设计的思想和实现的技巧. 废话不多说,jquery这么多年了分析都写烂了,老早以前就拜读过, 不过这几年都是做移动端,一直御用zepto, 最近抽出点时间把jquery ...
- MVC4做网站Demo进行重写的问题。
自从学习MVC4开始,边学边写这个demo,写了也有一年多了.开始觉得是一个小例子把所有的代码都写在一个项目中,边写边改越写越混乱,越到后来很多东西自己都理不清了.后来在群里跟 @怒放 在讨论这个问题 ...
- android标题栏下面弹出提示框(一) TextView实现,带动画效果
产品经理用的是ios手机,于是android就走上了模仿的道路.做这个东西也走了一些弯路,写一篇博客放在这里,以后自己也可用参考,也方便别人学习. 弯路: 1.刚开始本来用PopupWindow去实现 ...
- 可惜Java中没有yield return
项目中一个消息推送需求,推送的用户数几百万,用户清单很简单就是一个txt文件,是由hadoop计算出来的.格式大概如下: uid caller 123456 12345678901 789101 12 ...
- Rust初步(一):介绍
最近在研究Rust这个新的语言.那么Rust是什么呢? Rust是一个注重安全与速度的现代系统编程语言,通过在没有垃圾回收的情况下保证内存安全来实现它的目标,这使它成为一个在很多其它语言不适合的用例中 ...
- JavaSE高级之集合类
下面的内容是对java中的集合类进行的总结,过段时间会分享java的网路编程,多线程等内容,欢迎批评指正. 1.Java中的集合是用来存放对象的,即集合是对象的集合,对象是集合的元素,java AP ...
- 设计窘境:来自 Repository 的一丝线索,Domain Model 再重新设计
写在前面 阅读目录: 疑惑解读 设计窘境 一幅图的灵感 为嘛还是你-Repository 后记 上一篇<No zuo no die:DDD 应对具体业务场景,Domain Model 重新设计& ...
- spring源码分析之定时任务概述
Spring框架提供了TaskExcutor的异步执行和TashScheduler的任务定时执行接口,同样spring也提供了线程池或者CommonJ的代理. TaskExecutor的类型 Simp ...
- 安装infer整个过程
日期:2015-06-26 孟起 15:43:25 大神.. 孟起 15:43:38 我是不是照着这个安装 HelloWorld 15:45:05 直接找二进制文件安卓就行 孟起 15:46: ...
- 1Z0-053 争议题目解析688
1Z0-053 争议题目解析688 考试科目:1Z0-053 题库版本:V13.02 题库中原题为: 688.Which two statements are true about the compr ...