DropDownList查询
protected void btnGo_Click(object sender, EventArgs e) { var query1 = _Context.STO.AsQueryable();//根据产品别查 var query2 = _Context.STO.AsQueryable();//根据仓库编号查 var query3 = _Context.STO.AsQueryable();//根据仓库名称查 //根据数据框的填入情况完善以上三个查询 if (ddlProd.SelectedValue != "-1") { query1 = query1.Where(p=>p.PRODCODE == ddlProd.SelectedValue ); } if (txtNo.Text.Trim().Length > 0) { query2 = query2.Where(p=>p.STORNO == txtNo.Text ); } if (txtName.Text.Trim().Length > 0) { query3 = query3.Where(p => p.STORNAME.Contains(txtName.Text)); } //三个查询条件用交集 var query = query1.Intersect(query2).Intersect(query3); //绑定显示 Repeater1.DataSource = query; Repeater1.DataBind(); }
Input(Checkbox)查询
1.先填充数据
//填充区域 private void FillArea() { List<ItemData> list = new List<ItemData>();//新建一个ItemData类 List<string> temp = _Context.House.Select(p=>p.Area).Distinct().ToList();//去重查出区域 foreach (string s in temp) //遍历string 变成ItemData对象 { ItemData data = new ItemData(); data.Code = s; data.Name = s; list.Add(data); } //绑定数据 Repeater1.DataSource = list; Repeater1.DataBind(); } //填充租赁类型 private void FillRentType() { 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); } Repeater2.DataSource = list; Repeater2.DataBind(); } //填充房屋类型 private void FillHouseType() { List<ItemData> list = new List<ItemData>(); List<string> temp = _Context.House.Select(p => p.HouseType).Distinct().ToList(); foreach (string s in temp) { ItemData data = new ItemData(); data.Code = s; data.Name = s; list.Add(data); } Repeater3.DataSource = list; Repeater3.DataBind(); }
2.查询
//点击全选复选框,下面的条件复选框都会选上<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> 区 域 :<input id="chAreaAll" type="checkbox" onclick="checkAll(this, ‘ckarea‘)" />全选<br /> <br /> <asp:Repeater ID="Repeater1" runat="server"> <ItemTemplate> <input id="ckArea_<%#Eval("Code") %>" name="ckarea" type="checkbox" value="<%#Eval("Code") %>"/><span><%#Eval("Name") %></span> </ItemTemplate> </asp:Repeater> <br /> <br /> 租赁类型:<input id="ckRentTypeAll" type="checkbox" onclick="checkAll(this,‘ckrenttype‘)"/>全选<br /> <br /> <asp:Repeater ID="Repeater2" runat="server"> <ItemTemplate> <input id="ckRentType_<%#Eval("Code") %>" name="ckrenttype" type="checkbox" value="<%#Eval("Code") %>" /><span><%#Eval("Name") %></span> </ItemTemplate> </asp:Repeater> <br /> <br /> 房屋类型:<input id="ckHouseType" type="checkbox" onclick="checkAll(this,‘ckhousetype‘)" />全选<br /> <br /> <asp:Repeater ID="Repeater3" runat="server"> <ItemTemplate> <input id="ckHouseType_<%#Eval("Code") %>" name="ckhousetype" type="checkbox" value="<%#Eval("Code") %>" /><span><%#Eval("Name") %></span> </ItemTemplate> </asp:Repeater>
protected void Button1_Click(object sender, EventArgs e) { //区域查询 var query1 = _Context.House.AsQueryable(); if (Request["ckarea"] != null) { string area = Request["ckarea"]; string[] areas = area.Split(‘,‘); query1 = query1.Where(p=>areas.Contains(p.Area)); } //租赁类型查询 var query2 = _Context.House.AsQueryable(); if (Request["ckrenttype"] != null) { string renttype = Request["ckrenttype"]; string[] renttypes = renttype.Split(‘,‘); query2 = query2.Where(p=> renttypes.Contains(p.RentType)); } //房屋类型查询 var query3 = _Context.House.AsQueryable(); if (Request["ckhousetype"] != null) { string housetype = Request["ckhousetype"]; string[] housetypes = housetype.Split(‘,‘); query3 = query3.Where(p=> housetypes.Contains(p.HouseType)); } //关键字查询 var query4 = _Context.House.AsQueryable(); if (txtSearch.Text.Trim().Length > 0) { query4 = query4.Where(p=>p.KeyWord.Contains(txtSearch.Text)); } //取交集 绑定显示数据 var query = query1.Intersect(query2).Intersect(query3).Intersect(query4); ; Repeater4.DataSource = query; Repeater4.DataBind(); }
时间: 2024-10-01 06:33:41