How to efficiently filter lists based on multiple lists and combinations?

I have an aspx page with 5 lists. Each list can filter the other, so if the user selects an item in list 1, list 2, 3, 4, and 5 should be filtered. If the user selects an item in list 3, then list 1, 2, 4, and 5 should be filtered. The filter can move forward and back. Another scenario would be that I select an item in list 1, it filters the rest, and then I select an item in list 2, and then filters list 1 and others like a chaining effect. I also have to handle multiple options. This can get very confusing and I am curious if anyone can figure out a good way to handle this.

+1


source to share


1 answer


In my experience with similar problems, sometimes the simplest approach is to dynamically build everything in code.

You start with ListBox 1 on your page and disable / hide others if needed. Then you handle the ItemSelected event on ListBox 1 and add the corresponding items to ListBox 2 and enable / open it. Then handle the Selected Event on ListBox 2 in a similar question, cascading updates down your page / control.

If necessary, you can wrap the list boxes in the refresh pane so that updates do not affect other controls on the page.

Pseudocode:



aspx:
    <asp:ListBox runat="server" ID="lb1" OnSelectedIndexChanged="OnLB1Change" AutoPostBack="true" >
        <asp:ListItem Text="A" Value="A"></asp:ListItem>
        <asp:ListItem Text="B" Value="B"></asp:ListItem>
    </asp:ListBox>

      

code behind:

   protected void OnLB1Change(object sender, EventArgs e)
    {
        int val = ((ListBox)sender).SelectedIndex;

        switch (val)
        {
            case 0:
                //set up LB2 for values A
            break;
            case 1:
               //set up LB2 for values B
            break;

        }
    }

      

+1


source







All Articles