码迷,mamicode.com
首页 > 其他好文 > 详细

租房子分组交集查询

时间:2015-08-20 13:02:28      阅读:163      评论:0      收藏:0      [点我收藏+]

标签:

Html界面

<title></title>
<script language="javascript">
function CkAll(ckall,ckname){
var cks = document.getElementsByName(ckname);
for(var i=0;i<cks.length;i++)
{
cks[i].checked = ckall.checked;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>

区域:<input id="Checkbox1" type="checkbox" onclick="CkAll(this,‘CkArea‘)" />全选<br />
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<input id="CkArea_<%#Eval("Code") %>1" name="CkArea" type="checkbox" value="<%# Eval("Code") %>" /><span><%#Eval("Name") %></span>
</ItemTemplate>
</asp:Repeater>
<br />
租赁类型:<input id="Checkbox2" type="checkbox"onclick="CkAll(this, ‘CkRentType‘)" />全选<br />
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<input id="CkRentType_<%#Eval("Code") %>" type="checkbox" name="CkRentType" value="<%#Eval("Code") %>" /><span><%#Eval("Name") %></span>
</ItemTemplate>
</asp:Repeater>
<br />
房屋类型:<input id="Checkbox3" type="checkbox"onclick="CkAll(this, ‘CkHouseType‘)" />全选<br />
<asp:Repeater ID="Repeater3" runat="server">
<ItemTemplate>
<input id="CkHouseType_<%#Eval("Code") %>" type="checkbox" name="CkHouseType" value="<%#Eval("Code") %>" /><span><%#Eval("Name") %></span>
</ItemTemplate>
</asp:Repeater>
<br />
关键词:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<br />
<asp:Button ID="Button1" runat="server" Text="搜索" OnClick="Button1_Click" />
<br />
<asp:Repeater ID="Repeater4" runat="server">
<HeaderTemplate>
<table width="100%" border="1">
</HeaderTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
<ItemTemplate>
<tr>
<td><%#Eval("KeyWord") %></td>
<td><%#Eval("Area") %></td>
<td><%#Eval("SquareMeter") %></td>
<td><%#Eval("Rent") %></td>
<td><%#Eval("RentType") %></td>
<td><%#Eval("HouseType") %></td>
</tr>
</ItemTemplate>
</asp:Repeater>

</div>
</form>
</body>

 

 

 

代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Sousuo : System.Web.UI.Page
{
private HouseDataContext _Context = new HouseDataContext();
private void FillArea()
{
//定义封装类 新建类 造个集合
List<House> list = new List<House>();
//再造个临时集合 查询数据库中用Selectri找Area列 去掉重复吧 字段找出来
List<string> list2 = _Context.House.Select(p => p.Area).Distinct().ToList();
//循环遍历每一个 吧Area列的值从数据库拿出来 送到S上去 把Data的Code和Name送到集合中区
foreach(string s in list2)
{
House data = new House();
data.Code = s;
data.Name = s;
list.Add(data);
}
//把查出来的集合 绑定到Repeater1的界面上去
Repeater1.DataSource = list;
Repeater1.DataBind();
}
private void FillRentType()
{
List<House> list = new List<House>();
List<string> list2 = _Context.House.Select(p => p.RentType).Distinct().ToList();
foreach(string s in list2)
{
House data = new House();
data.Code = s;
data.Name = s;
list.Add(data);
}
Repeater2.DataSource = list;
Repeater2.DataBind();
}
private void FillHouseType()
{
List<House> list = new List<House>();
List<string> list2 = _Context.House.Select(p => p.HouseType).Distinct().ToList();
foreach(string s in list2)
{
House data = new House();
data.Name = s;
data.Code = s;
list.Add(data);
}
Repeater3.DataSource = list;
Repeater3.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
FillArea();
FillHouseType();
FillRentType();
}
protected void Repeater1_ItemCommand(object source, RepeaterCommandEventArgs e)
{

}
protected void Button1_Click(object sender, EventArgs e)
{
var var1 = _Context.House.AsQueryable();
if(Request["CkArea"]!=null)
{
string strarea = Request["CkArea"];
string[] areas = strarea.Split(‘,‘);
var1 = var1.Where(p => areas.Contains(p.Area));
}
var var2 = _Context.House.AsQueryable();
if(Request["CkRentType"]!=null)
{
string rentType = Request["CkRentType"];
string[] rent = rentType.Split(‘,‘);
var2 = var2.Where(p => rent.Contains(p.RentType));
}
var var3 = _Context.House.AsQueryable();
if (Request["CkHouseType"] != null)
{
string housetype = Request["CkHouseType"];
string[] houses = housetype.Split(‘,‘);
var3 = var3.Where(p => houses.Contains(p.HouseType));
}

var var4 = _Context.House.AsQueryable();
if(TextBox1.Text.Trim().Length>0)
{
var4 = var4.Where(p => p.KeyWord.Contains(TextBox1.Text));
}


var var = var1.Intersect(var2).Intersect(var4).Intersect(var3);


Repeater4.DataSource = var;
Repeater4.DataBind();
}

}

租房子分组交集查询

标签:

原文地址:http://www.cnblogs.com/tianxuan/p/4744585.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!