类似京东商城筛选模块
2011-12-20 09:51
148 查看
最近做了个类似京东商城筛选模块的功能,在网上找了些资料,再加了些自己的思路做了这样一个功能,在这里分享一下,主要针对新手,希望大家共同探讨
前台是两个repeater嵌套
后台
View Code
这样的基本效果就实现了
前台是两个repeater嵌套
<asp:Repeater ID="rptList" runat="server" onitemdatabound="rptList_ItemDataBound"> <ItemTemplate> <tr> <td><%# Eval("PropertyName")%></td> <td><asp:Literal ID="litPropertyValueAll" runat="server" /></td> <td> <asp:Repeater ID="rptValue" runat="server" OnItemDataBound="rptValue_ItemDataBound"> <ItemTemplate> <asp:Label ID="lblHidden" runat="server" Visible="false" /> <span style="color:#ccc;">|</span> <asp:Literal ID="litPropertyValue" runat="server" /> </ItemTemplate> </asp:Repeater> </td> </tr> </ItemTemplate> </asp:Repeater>
后台
View Code
/// <summary> /// 属性数据绑定 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void rptList_ItemDataBound(object sender, RepeaterItemEventArgs e) { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Repeater rpt = (Repeater)e.Item.FindControl("rptValue"); int id = ((ProductCategorySearchPropertyModel)e.Item.DataItem).ID; rpt.DataSource = Product_Category_SearchProperty_ValueBLL.GetPropertyValue(id); rpt.DataBind();
#region 所有属性 //所有条件 string allProperty = ""; foreach (RepeaterItem item in rpt.Items) { Label lab = (Label)item.FindControl("lblHidden"); allProperty = lab.Text; } Literal litPropertyValue = (Literal)e.Item.FindControl("litPropertyValueAll"); litPropertyValue.Text = allProperty; #endregion } }
/// <summary> /// 属性值数据绑定 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void rptValue_ItemDataBound(object sender, RepeaterItemEventArgs e) { #region 解析Url属性参数 //解析Url传的属性参数 if (!string.IsNullOrEmpty(searchPropertyIDReq)) { ArrayList tempSearchPropertyValueIDArrayList = new ArrayList(); string[] tempSearchPropertyValueIDArray = searchPropertyIDReq.Split('-'); foreach (string item in tempSearchPropertyValueIDArray) { if (string.IsNullOrEmpty(item)) { continue; } try { Convert.ToInt32(item); } catch { continue; } tempSearchPropertyValueIDArrayList.Add(Convert.ToInt32(item)); } searchPropertyValueIDArray = (int[])tempSearchPropertyValueIDArrayList.ToArray(typeof(int)); } #endregion #region 绑定商品列表 this.rptProductList.DataSource = ProductBLL.SearchProduct(searchPropertyValueIDArray); this.rptProductList.DataBind(); #endregion #region rptValue 数据绑定 if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { string curPropertyName = DataBinder.Eval(e.Item.DataItem, "PropertyName").ToString(); string curPropertyValue = DataBinder.Eval(e.Item.DataItem, "PropertyValue").ToString(); //当前RUL string curPropertyValueID = DataBinder.Eval(e.Item.DataItem, "ID").ToString(); string cNo = DataBinder.Eval(e.Item.DataItem, "cNo").ToString(); bool isHasCurrentPropertyName = false; int? urlPropertyValueID = null; if (searchPropertyValueIDArray != null) { foreach (int searchPropertyValueID in searchPropertyValueIDArray) { ProductCategorySearchPropertyValueModel properValue = Product_Category_SearchProperty_ValueBLL.GetPropertyValueA(searchPropertyValueID); int searchPropertyID = properValue.SearchPropertyID; ProductCategorySearchPropertyModel searchProperty = Product_Category_SearchPropertyBLL.GetSearchPropertyA(searchPropertyID); if (searchProperty.PropertyName == curPropertyName) { urlPropertyValueID = searchPropertyValueID; isHasCurrentPropertyName = true; break; } } } //原始URL string searchPropertyIDUrl = ""; if (searchPropertyValueIDArray != null) { foreach (int searchPropertyValueID in searchPropertyValueIDArray) { if (searchPropertyValueID != urlPropertyValueID) { searchPropertyIDUrl += "-" + searchPropertyValueID.ToString(); } } } //具体属性 Literal litPropertyValue = (Literal)e.Item.FindControl("litPropertyValue"); Label hiddenValue = (Label)e.Item.FindControl("lblHidden"); if (isHasCurrentPropertyName) { if (urlPropertyValueID != null && urlPropertyValueID.ToString() == curPropertyValueID) { litPropertyValue.Text = "<a href=\"" + cNo + searchPropertyIDUrl + "-" + curPropertyValueID + ".aspx\" class=\"curSearchProperty\" isCurrent=\"true\">" + curPropertyValue + "</a>"; } else { litPropertyValue.Text = "<a href=\"" + cNo + searchPropertyIDUrl + "-" + curPropertyValueID + ".aspx\" class=\"normal\">" + curPropertyValue + "</a>"; } } else { litPropertyValue.Text = "<a href=\"" + cNo + searchPropertyIDUrl + "-" + curPropertyValueID + ".aspx\" class=\"normal\">" + curPropertyValue + "</a>"; } hiddenValue.Text = "<a href=\"" + cNo + searchPropertyIDUrl + ".aspx\" class=\"allProperty\" isCurrent=\"true\">全部</a>"; } #endregion }
这样的基本效果就实现了
相关文章推荐
- 一个类似京东商城那种多条件筛选效果
- access导入报错 请求筛选模块被配置为拒绝超过请求内容长度的请求
- 写了一个内核模块 实现简单的类似ps命令
- python模块整理8-glob(类似grep)和fnmatch(匹配文件名)
- 类似于京东商城等的商品分类搜索筛选功能实现
- 输入文字自动筛选--类似百度的功能(onchange与oninput和 onpropertychange 两者的区别)
- [iis7]请求筛选模块被配置为拒绝包含双重转义序列的请求。HTTP 错误 404.11 - Not Found
- HTTP 错误 404.8 - Not Found,请求筛选模块被配置为拒绝包含 hiddenSegment 节的 URL 中的路径
- 仿京东商城多条件筛选
- HTTP 错误 404.15 - Not Found 请求筛选模块被配置为拒绝包含的查询字符串过长的请求。
- Python使用re模块实现信息筛选的方法
- 基于动态代理仿写的一个类似XUtils 3.0的ioc注解模块
- 文件上传:HTTP错误 404.13-Not Found 请求筛选模块被配置为拒绝超过请求内容长度的请求
- 类似通讯录侧边滑动筛选的sidebar
- 请求筛选模块被配置为拒绝超过请求内容长度的请求
- IIS请求筛选模块被配置为拒绝超过请求内容长度的请求
- 请求筛选模块被配置为拒绝包含双重转义序列的请求
- 类似京东商城客户端应用iOS源码
- 【工具设置】解决“请求筛选模块被配置为拒绝包含双重转义序列的请求”错误
- IIS8.0, IIS7.0提示“请求筛选模块被配置为拒绝包含双重转义序列的请求”处理办法