Rent intersection Query

Source: Internet
Author: User

Web interface

<title></title>
<script language= "JavaScript" >
function Checkall (Ckall, Ckname) {
var cks = Document.getelementsbyname (ckname);
for (var i = 0; i < cks.length; i++) {
cks[i].checked = ckall.checked;
}
}
</script>
<body>
<form id= "Form1" runat= "Server" >
<div>

Area: <input id= "Ckareaall" type= "checkbox" onclick= "Checkall (This, ' Ckarea ')"/> Select all <br/>
<asp:repeater id= "Repeater1" runat= "Server" onitemcommand= "Repeater1_itemcommand" >
<ItemTemplate>
<input id= "ckarea_<%# eval (" code ")%>" name= "Ckarea" type= "checkbox" Value= "<%# Eval (" code ")%>"/> <span><%# Eval ("Name")%></span>
</ItemTemplate>
</asp:Repeater>
<br/>
<br/>
Lease type: <asp:checkbox id= "Ckrenttypeall" runat= "Server" text= "Select All"/>
<br/>
<asp:checkboxlist id= "CheckBoxList1" runat= "server" repeatdirection= "horizontal" repeatlayout= "Flow" >
</asp:CheckBoxList>
<br/>
<br/>
House type: <input id= "Ckhousetypeall" type= "checkbox" onclick= "Checkall (This, ' Ckhousetype ')"/> Select all <br/>
<asp:literal id= "Literal1" runat= "Server" ></asp:Literal>
<br/>
Keywords: <asp:textbox id= "TXT" runat= "server" ></asp:TextBox>
<br/>
<br/>
<asp:button id= "Btnfind" runat= "server" text= "search" onclick= "Btnfind_click"/>

<br/>
<br/>
<asp:repeater id= "Repeater2" 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>

Code interface

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

public partial class _default:system.web.ui.page
{
Private Mydbdatacontext _context = new Mydbdatacontext ();
#region = = Fill check box = =
private void Fillarea ()
{
Preparing data
list<itemdata> list = new list<itemdata> ();
list<string> temp = _context.house.select (p = = P.area). Distinct (). ToList ();
foreach (string s in temp)
{
ItemData data = new ItemData ();
Data. Code = s;
Data. Name = s;
List. ADD (data);
}
Interface display
Repeater1.datasource = list;
Repeater1.databind ();
}
private void Fillrenttype ()
{
Preparing data
list<itemdata> list = new list<itemdata> ();
list<string> temp = _context.house.select (p = = p.renttype). Distinct (). ToList ();
foreach (string s in temp)
{
ItemData data = new ItemData ();
Data. Code = s;
Data. Name = s;
List. ADD (data);
}
Interface display
Checkboxlist1.datasource = list;
Checkboxlist1.datatextfield = "Name";
Checkboxlist1.datavaluefield = "Code";
Checkboxlist1.databind ();
}
private void Fillhousetype ()
{
Preparing data
list<string> temp = _context.house.select (p = = p.housetype). Distinct (). ToList ();

Interface display
foreach (string s in temp)
{
Literal1.text + = "<input type= ' checkbox ' id=" + S + "name= ' ckhousetype ' value= '" + S + "' >" + S;
}


}
#endregion
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
Fillarea ();
Fillrenttype ();
Fillhousetype ();
}
}

protected void Btnfind_click (object sender, EventArgs e)
{
#region = = Combo Query = =
//Selection query
var query1 = _con Text. House.asqueryable ();
if (request["Ckarea"]! = null)
{
String strarea = request["Ckarea"];
string[] areas = Strarea. Split (', ');
Query1 = Query1. Where (p = = areas. Contains (P.area));
}

//Lease type query
var query2 = _context.house.asqueryable ();
list<string> renttypes = new list<string> ();
foreach (ListItem li in Checkboxlist1.items)
{
if (li. Selected = = True)
{
Renttypes.add (li. Value);
}
}
if (Renttypes.count > 0)
{
Query2 = Query2. Where (p = renttypes.contains (P.renttype));
}
//housing type query
var query3 = _context.house.asqueryable ();
if (request["Ckhousetype"]! = null)
{
Strin G Strhousetype = request["Ckhousetype"];
string[] Housetypes = Strhousetype. Split (', ');
Query3 = Query3. Where (p = housetypes.contains (P.housetype));
}

Keyword Query
var query4 = _context.house.asqueryable ();
if (txt. Text.trim (). Length > 0)
{
Query4 = Query4. Where (p = p.keyword.contains (txt. Text));
}

Integration
var query = Query1. Intersect (Query2). Intersect (Query3). Intersect (QUERY4);

Repeater2.datasource = query;
Repeater2.databind ();
#endregion
}

Rent intersection Query

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.