使用纯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" />
&nbsp;价格<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">
当前第&nbsp<span id="nowye"></span>&nbsp页&nbsp&nbsp共&nbsp<span id="allye"></span>&nbsp页
<input id="btn_first" type="button" value="首页" />&nbsp<input id="btn_prev" type="button" value="上一页" />&nbsp<input type="button" id="btn_next" value="下一页" />&nbsp<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分页与组合查询配合使用的更多相关文章

  1. Webform(分页与组合查询配合使用)

    1.封装实体类 2.写查询方法 //SubjectData类 public List<Subject> Select(string name) { List<Subject> ...

  2. Webform(Linq高级查、分页、组合查询)

    一.linq高级查 1.模糊查(包含) 1 public List<User> Select(string name) 2 { 3 return con.User.Where(r => ...

  3. webform 分页、组合查询综合使用

    界面: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx ...

  4. Webform(分页、组合查询)

    一.分页 1.写查询方法: public List<Student> Select(int PageCount, int PageNumber) {//PageCount为每页显示条数,P ...

  5. WebForm 分页与组合查询

    1.封装实体类 2.写查询方法 //SubjectData类 public List<Subject> Select(string name) { List<Subject> ...

  6. Linq的分页与组合查询的配合使用

    1.首先使用Linq连接数据库,并扩展属性 public partial class User { public string SexStr { get { string end = "&l ...

  7. WebForm 分页、组合查询--2017年1月5日

    sql = "select * from Commodity"; hs = new Hashtable(); if (txt_name.Text.Trim() != "& ...

  8. django项目中的ajax分页和条件查询。

    1,路由 #主页面路由 re_path('article/article_list/', article.article_list,name='article/article_list/'), #分页 ...

  9. linq分页组合查询

    一.linq高级查 1.模糊查(字符串包含) 1 public List<User> Select(string name) 2 { 3 return con.User.Where(r = ...

随机推荐

  1. C#设计模式-外观模式

    在软件开发过程中,客户端程序经常会与复杂系统的内部子系统进行耦合,从而导致客户端程序随着子系统的变化而变化,然而为了将复杂系统的内部子系统与客户端之间的依赖解耦,从而就有了外观模式,也称作 ”门面“模 ...

  2. 剖析twemproxy前言

    又是喜闻乐见的新坑,前面的mysql协议,当我在解读go-mysql包的时候,会重新讲到,至于Leetcode的更新会与go语言同步.关于这个redis的新坑,目前打算通过剖析twemproxy源码来 ...

  3. 谈谈StringBuffer和StringBuilder

    (1) 速度 在执行速度方面的比较:StringBuilder > StringBuffer > String ①String 是不可变的对象(String类源码中存放字符的数组被声明为f ...

  4. Codeforces Round #323 (Div. 2) C.GCD Table

    C. GCD Table The GCD table G of size n × n for an array of positive integers a of length n is define ...

  5. codeforces C. Vanya and Scales

    C. Vanya and Scales Vanya has a scales for weighing loads and weights of masses w0, w1, w2, ..., w10 ...

  6. MySQL学习笔记十二:数据备份与恢复

    数据备份 1.物理备份与逻辑备份 物理备份 物理备份就是将数据库的数据文件,配置文件,日志文件等复制一份到其他路径上,这种备份速度一般较快,因为只有I/O操作.进行物理备份时,一般都需要关闭mysql ...

  7. codefordream 关于js中级训练

    中级训练接着就紧锣密鼓的开始了. 首先是关于变量,变量的作用是给一个数据值标注名称. 注:JavaScript中变量名,函数名,参数名的命名规范:至少由字母,下划线,美元符号,数字其中的一种组成,但不 ...

  8. EF CodeFirst EntityTypeConfiguration 自关联映射配置

    实体示例代码: public class Message { public Message() { } public int ID { get; private set; } public strin ...

  9. php后管理分类导航菜单

    <!DOCTYPE> <html> <head> <meta http-equiv="Content-type" content=&quo ...

  10. Kooboo CMS - Html.FrontHtml[Helper.cs] 各个方法详解

    下面罗列了方法详解,每一个方法一篇文章. Kooboo CMS - @Html.FrontHtml().HtmlTitle() 详解 Kooboo CMS - Html.FrontHtml.Posit ...