How do I constrain Databound CheckBoxLists

I have a six check box lists to select products (two are shown below). All of the data resides in a table, so I iterate through all of the checked boxes to construct a SELECT statement which in turn lists my results regardless of which items are checked across the various check box lists. This works perfectly to fetch the results I want. Now I want to constrain the results in each of those check box lists based on selections in other check box lists.

For example – if you go to Zappos, and select Adidas from the “Brand” options, then the “Style”, “Color”, and “Materials” lists will all only show options available from Adidas. This is what I want to accomplish, but not in a hierarchy – so you don’t have to start with brand, you could start with any of the check box lists and the others will automatically restrict.

I feel like the best way to do that for me is to create a SELECT statement for each CBL, but I am completely stuck. Here is what I have so far:

<h3 id="brandheader" class="NavHeader">Brand</h3><!--end NavHeader-->
<div id="brandoptionsCBL" class="subnav">
    <asp:CheckBoxList id="CheckBoxListBrand" Cssclass="CBL" runat="server" AutoPostBack="True" DataSourceID="SqlMHIPlumbingVendor" DataTextField="Vendor" DataValueField="Vendor" RepeatColumns="1" OnSelectedIndexChanged="CheckBoxListBrand_SelectedIndexChanged"></asp:CheckBoxList>
    <asp:SqlDataSource runat="server" id="SqlMHIPlumbingVendor" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" SelectCommand="SELECT DISTINCT [Vendor] FROM [MHIplumbing] WHERE ([Vendor] <> @Vendor) ORDER BY [Vendor]">
    <SelectParameters>
        <asp:Parameter DefaultValue="0" Name="Vendor" Type="String" />
    </SelectParameters>        
    </asp:SqlDataSource>
</div><!--end brandoptionsCBL-->

<h3 id="collectionheader" class="NavHeader">Collection</h3><!--end NavHeader-->
<div id="collectionoptionsCBL" class="subnav">
    <asp:CheckBoxList id="CheckBoxListCollection" Cssclass="CBL" runat="server" AutoPostBack="True" DataSourceID="SqlMHIPlumbingCollection" DataTextField="Collection" DataValueField="Collection" RepeatColumns="1" OnSelectedIndexChanged="CheckBoxListCollection_SelectedIndexChanged"></asp:CheckBoxList>
<asp:SqlDataSource ID="SqlMHIPlumbingCollection" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>" OnSelected="SqlMHIPlumbingCollection_Selected" ></asp:SqlDataSource>
    

.

public partial class bath_plumbing : System.Web.UI.Page
{
    String selectit = "SELECT SKU, Collection, Vendor, Description, Note, DISC, Category, Product, SubCategory, Finish, Stock FROM MHIplumbing WHERE " ;
    String selectCBLCollection = "SELECT DISTINCT Collection FROM MHIplumbing WHERE ";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
        {
            LabelReferrer.Text += " Is PostBack";
            String controlname = Page.Request.Params["__EVENTTARGET"];
            if (String.IsNullOrEmpty(controlname))
            {
                ProcessQueryString();
            }
        }
        if (!IsPostBack)
        {

        }
    }

    protected void Page_LoadComplete(object sender, EventArgs e)
    {

    }

    protected void CheckBoxListBrand_SelectedIndexChanged(object sender, EventArgs e)
    {
        LabBrand.Text = "";
        LabBrandCBL.Text = "";
        String whereis = " (MHIplumbing.Vendor = '";
        String changeCBLCollection = " (Vendor = '";

        CheckBoxList ckl = (CheckBoxList)sender;
        Boolean first = true;
        Boolean somechecked = false;
        selectionbrand.Text = "";

        foreach (ListItem li in ckl.Items)
        {
            if (li.Selected == true)
            {
                if (first)
                {
                    whereis += li.Value;
                    changeCBLCollection += li.Value;
                    first = false;
                }
                else
                {
                    whereis += "') OR (MHIplumbing.Vendor = '" + li.Value;
                    changeCBLCollection += "') OR (Vendor = '" + li.Value;
                }
                selectionbrand.Text += " " + li.Text;
                somechecked = true;
            }
        }
        whereis += "')";
        changeCBLCollection += "')";
        if (somechecked)
        {
            LabBrand.Text += whereis;
            LabBrandCBL.Text += changeCBLCollection;
        }

        Updatepage();
    }
protected void CheckBoxListBrand_Set()
{
    LabBrand.Text = "";
    LabBrandCBL.Text = "";
    String whereis = " (MHIplumbing.Vendor = '";
    String changeCBLCollection = " (Vendor = '";
    CheckBoxList ckl = CheckBoxListBrand;
    Boolean first = true;
    Boolean somechecked = false;
    foreach (ListItem li in ckl.Items)
    {
        if (li.Selected == true)
        {
            if (first)
            {
                whereis += li.Value;
                changeCBLCollection += li.Value;
                first = false;
            }
            else
            {
                whereis += "') OR (MHIplumbing.Vendor = '" + li.Value;
                changeCBLCollection += "') OR (Vendor = '" + li.Value;
            }
            somechecked = true;
        }
    }
    whereis += "')";
    changeCBLCollection += "')";
    if (somechecked)
    {
        LabBrand.Text += whereis;
        LabBrandCBL.Text += changeCBLCollection;
    }
    //Updatepage();
}

protected void CheckBoxListCollection_SelectedIndexChanged(object sender, EventArgs e)
{
    LabCollection.Text = "";
    String whereis = " (MHIplumbing.Collection = '";
    CheckBoxList ckl = (CheckBoxList)sender;
    Boolean first = true;
    Boolean somechecked = false;
    selectioncollection.Text = "";
    foreach (ListItem li in ckl.Items)
    {
        if (li.Selected == true)
        {
            if (first)
            {
                whereis += li.Value;
                first = false;
            }
            else
            {
                whereis += "') OR (MHIplumbing.Collection = '" + li.Value;
            }
            selectioncollection.Text += " " + li.Text;
            somechecked = true;
        }
    }
    whereis += "')";
    if (somechecked)
    {
        LabCollection.Text += whereis;
    }
    Updatepage();
}
protected void CheckBoxListCollection_Set()
{
    LabCollection.Text = "";
    String whereis = " (MHIplumbing.Collection = '";
    CheckBoxList ckl = CheckBoxListCollection;
    Boolean first = true;
    Boolean somechecked = false;
    foreach (ListItem li in ckl.Items)
    {
        if (li.Selected == true)
        {
            if (first)
            {
                whereis += li.Value;
                first = false;
            }
            else
            {
                whereis += "') OR (MHIplumbing.Collection = '" + li.Value;
            }
            somechecked = true;
        }
    }
    whereis += "')";
    if (somechecked)
    {
        LabCollection.Text += whereis;
    }
    //Updatepage();
}

protected void ListViewResults_ItemCreated(object sender, ListViewItemEventArgs e)
{

}
protected void SqlResults_Selected(object sender, SqlDataSourceStatusEventArgs e)
{
    LabelSelected.Text = e.AffectedRows.ToString();
}
protected void SqlMHIPlumbingCollection_Selected(object sender, SqlDataSourceStatusEventArgs e)
{

}


protected void Updatepage()
{
    plumbingsearchlabel.Visible = true;
    Boolean first = true;
    if (LabBrand.Text != "" || LabBrandCBL.Text != "" || LabCollection.Text != "")
    {
        SqlResults.SelectCommand = selectit;
        SqlMHIPlumbingCollection.SelectCommand = selectCBLCollection;
        if (LabBrand.Text != "")
        {
            if (first)
            {
                SqlResults.SelectCommand += LabBrand.Text;
                first = false;
            }
            else
            {
                SqlResults.SelectCommand += " AND " + LabBrand.Text;
            }
        }
        if (LabBrandCBL.Text != "")
        {
            if (first)
            {
                SqlMHIPlumbingCollection.SelectCommand += LabBrandCBL.Text;
                first = false;
            }
            else
            {
                SqlMHIPlumbingCollection.SelectCommand += " AND " + LabBrandCBL.Text;
            }
        }
        if (LabCollection.Text != "")
        {
            if (first)
            {
                SqlResults.SelectCommand += LabCollection.Text;
                first = false;
            }
            else
            {
                SqlResults.SelectCommand += " AND " + LabCollection.Text;
            }
        }

        SqlResults.SelectCommand += " ORDER BY MHIplumbing.SKU ";
        SqlMHIPlumbingCollection.SelectCommand += " ORDER BY Collection ";
    }
    else
    {
        SqlResults.SelectCommand = "";
        SqlMHIPlumbingCollection.SelectCommand = "";
    }
    LabSelect.Text = SqlResults.SelectCommand;
    LabCBLCollection.Text = SqlMHIPlumbingCollection.SelectCommand;
    ListViewResults.DataBind();
}

I’m getting “Incorrect syntax near the keyword ‘AND'” that I think is provoked here…

    if (LabBrandCBL.Text != "")
    {
        if (first)
        {
            SqlMHIPlumbingCollection.SelectCommand += LabBrandCBL.Text;
            first = false;
        }
        else
        {
            SqlMHIPlumbingCollection.SelectCommand += " AND " + LabBrandCBL.Text;
        }
    }

I “built” the SELECT statement as I scrolled through the code, and it looked correct, but obviously I’m missing something.

I appreciate any help with this method or if you could point me in the direction of a tutorial for a better method that would work with what I’ve done so far, I’m open to all options.

Thank you!

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật