ASP.NET ListBox - Knowledge Base

« Back to Knowledge Base list

Multiple parameters for unlimited detail levels


I am using the master / detail feature of the ListBox, with three levels. In the first level the users select the state, in the second one they select the city and in the third one they select the zip code. For the third level I need to receive both the state selected in the first list and the city selected in the second list, so I can load the appropriate zip codes from the database in the third list. Is there a way to do this?


Yes, this is possible. Based on the "aspnet_master_detail_unlimited.aspx" sample from the Suite (in the ListBox folder), you need to make the following changes:

- for the DataSourceControl that populates the third level, you need to add an extra parameter and change the SQL query to use this parameter. For example:

<asp:SqlDataSource ID="sds3" ...>
            <asp:Parameter Name="CityID" Type="Int32" />
            <asp:Parameter Name="StateID" Type="Int32" />

- in the event handler for the "LoadingItems" event of the second detail level you need to store the selected value of the first level into a Session variable:

protected void CitiesList_LoadingItems(object sender, ListBoxLoadingItemsEventArgs e)
        if (!string.IsNullOrEmpty(e.Text))
            sds2.SelectParameters[0].DefaultValue = e.Text;
            Session["SelectedState"] = e.Text;

- in the event handler for the "LoadingItems" event of the third detail level you need to use the Session variable to populate the second parameter of the DataSourceControl of the third detail level:

protected void ZipCodesList_LoadingItems(object sender, ListBoxLoadingItemsEventArgs e)
        if (!string.IsNullOrEmpty(e.Text))
            sds3.SelectParameters[0].DefaultValue = e.Text;
            sds3.SelectParameters[1].DefaultValue = Session["SelectedState"].ToString();
} Home 
ListBox Home   
ListBox Home 
Examples - 56
Appearance - 2 
Live Styles 
Different Styles New 
Load on Demand - 3 
Load Items on Demand 
Load Items on Demand with Paging  
Virtual Scrolling  
Multi-Columns - 5 
Grid-like Multi-Columns  
Grid-like Multi-Columns & Tooltips New 
Multiple Rows and Columns  
Load multi Columns on Demand  
State Selector  
Items with Icons - 4 
Items with Icons  
Grid-like Multi-Columns with Icons  
Multiple Rows and Columns with Icons  
Icons from Database New 
Templates - 4 
Item Templates  
Header Templates  
Dynamic Header Templates New 
Populating with Data - 5 
Generic Collections  
Item Selection - 6 
Single Item Selection  
Multi Item Selection  
Get Selected Item  
Get Selected Items  
Set Selected Item New 
Set Selected Items New 
Master/Detail - 3 
Unlimited Detail Levels  
Cascading ListBoxes  
Integration - 8 
Items with ASP.NET CheckBoxes  
Items with Obout CheckBoxes  
Select All ASP.NET CheckBoxes New 
Select All Obout CheckBoxes New 
CheckBoxes on Multiple Columns New 
RadioButtons inside ListBox  
ListBox inside Grid  
Validate with ASP.NET Validators New 
Settings - 3 
Server-Side API - 4 
Server-Side Events  
Enable / Disable  
Get Values from Multiple Columns New 
Tooltips New 
Client-Side API - 8 
Client-Side Events  
Add / Remove Items  
Add Multi-Column Items New 
Enable / Disable  
Get Selected Item  
Reset Selection New 
Select / Deselect All Items New 
Move Items New 
Appearance Customization - 1 
Aligning Items New 
Knowledge Base - 1 
Knowledge Base 
Documentation - 11 
Client-Side API 
Tutorials - 2 
Appearance - 1 
CSS Tutorial  
Configuration - 1 
Using the correct path