• 类似京东商城筛选模块


    最近做了个类似京东商城筛选模块的功能,在网上找了些资料,再加了些自己的思路做了这样一个功能,在这里分享一下,主要针对新手,希望大家共同探讨

    前台是两个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

    }

    这样的基本效果就实现了


     

  • 相关阅读:
    尚硅谷JavaWeb篇
    malloc 的线程安全与不可重入性
    MVCC 的一些总结
    LINUX网络子系统中DMA机制的实现
    JDK动态代理的实现原理
    Linux Polkit 权限提升漏洞预警(CVE20214034)
    [译]深入了解现代web浏览器(一)
    go语言使用redis实现异步任务
    Python 金额保留两位小数
    Django admin filter_horizontal 将多对多字段左右编辑
  • 原文地址:https://www.cnblogs.com/Kiss920Zz/p/2294225.html
Copyright © 2020-2023  润新知