This is a migrated thread and some comments may be shown as answers.

Dual Combobox : How to pre-populate with selected values?

3 Answers 213 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Carlo
Top achievements
Rank 1
Carlo asked on 13 Feb 2009, 01:29 PM
Hi There

I've got a dual combobox which I would like to prepopulate with values from querystring to keep the state persistent.

The problem is that when I load the child dropdown from server side and set the selected value, and then change the parent dropdown from the client side, it does not fire the child dropdown to populate with new values based on parent combo.

Any suggestions?

Here is my code :

<telerik:RadComboBox ID="ddnRegion" runat="server" Skin="Default" OnClientSelectedIndexChanging="LoadTowns" Width="180px" EnableLoadOnDemand="true" /> 
            <br /> 
            <br /> 
            <telerik:RadComboBox ID="ddnTown" runat="server" Width="180px" Skin="Default" EnableLoadOnDemand="true" 
            OnClientItemsRequested="ItemsLoaded" OnItemsRequested="ddnTown_ItemsRequested" /> 
 
 
<script type="text/javascript"
    function LoadTowns(combo, eventarqs) { 
        var townCombo = $find("<%=ddnTown.ClientID%>"); 
        var item = eventarqs.get_item(); 
        townCombo.set_text("Loading..."); 
 
        if (item.get_index() > 0) { 
            townCombo.requestItems(item.get_value(), false); 
        } 
        else { 
            townCombo.set_text(" "); 
            townCombo.clearItems(); 
        } 
    } 
 
    function ItemsLoaded(combo, eventarqs) { 
        var townCombo = $find("<%=ddnTown.ClientID%>"); 
        if (combo.get_items().get_count() > 0) { 
            combo.set_text(combo.get_items().getItem(0).get_text()); 
            combo.get_items().getItem(0).highlight(); 
        } 
        combo.showDropDown(); 
    } 
</script> 


protected void Page_Load(object sender, EventArgs e) 
    { 
        if (!Page.IsPostBack && !Page.IsCallback) 
        { 
            //first populate dropdowns 
            LoadRegions(); 
             
            if (Request.QueryString["region"] != null && Request.QueryString["region"] != "" && Request.QueryString["town"] != null && Request.QueryString["town"] != ""
            { 
                LoadTowns(Request.QueryString["region"]); 
            } 
 
            LoadServices(); 
        } 
    } 
 
void LoadRegions() 
    { 
        CMSManager manager = new CMSManager(dbConn()); 
        ddnRegion.DataSource = manager.GettblRegions(); 
        ddnRegion.DataTextField = "RegionName"
        ddnRegion.DataValueField = "RegionId"
        ddnRegion.DataBind(); 
 
        ddnRegion.Sort = RadComboBoxSort.Ascending; 
        ddnRegion.SortItems(); 
 
        ddnRegion.Items.Insert(0, new RadComboBoxItem("[Select a Region]")); 
 
 
        foreach (RadComboBoxItem item in ddnRegion.Items) 
        { 
            item.ToolTip = item.Text; 
        } 
 
        if (Request.QueryString["region"] != null && Request.QueryString["region"] != ""
        { 
            ddnRegion.SelectedIndex = ddnRegion.Items.IndexOf(ddnRegion.Items.FindItemByValue(Request.QueryString["region"])); 
        } 
    } 
 
    void LoadTowns(string regionId) 
    { 
        CMSManager manager = new CMSManager(dbConn()); 
        ddnTown.DataSource = manager.GettblTownsByRegionID(Convert.ToInt32(regionId)); 
        ddnTown.DataTextField = "TownName"
        ddnTown.DataValueField = "TownId"
        ddnTown.DataBind(); 
 
        ddnTown.Sort = RadComboBoxSort.Ascending; 
        ddnTown.SortItems(); 
 
        ddnTown.Items.Insert(0, new RadComboBoxItem("[Select a Town]")); 
 
        foreach (RadComboBoxItem item in ddnTown.Items) 
        { 
            item.ToolTip = item.Text; 
        } 
 
        if (Request.QueryString["region"] != null && Request.QueryString["region"] != "" && Request.QueryString["town"] != null && Request.QueryString["town"] != ""
        { 
            ddnTown.SelectedIndex = ddnTown.Items.IndexOf(ddnTown.Items.FindItemByValue(Request.QueryString["town"])); 
        } 
    } 
 
    protected void ddnRegion_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e) 
    { 
        LoadRegions(); 
    } 
 
    protected void ddnTown_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e) 
    { 
        LoadTowns(e.Text); 
    } 


Any help will be appreciated.

Many thanks!


3 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 16 Feb 2009, 02:29 PM
Hello Carlo,

I am not to understand the scenario, could you please send us steps to reproduce the issue with more detailed explanation? Thanks

All the best,
Yana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Carlo
Top achievements
Rank 1
answered on 16 Feb 2009, 02:51 PM
Ok, I will try to explain :

I have 2 combos in a admin page :
The first combo is to select a Region / State (ie. Florida)

The second combo is to select a Town (ie. Miami)

Upon selection of the Region , the Town call is made and the Town combo is populated.

Once the user clicks submit, the selected values of the combos are saved.

When the user comes back onto the page, the preselected values will be passed in (eg. pagename.aspx?regionId=10&townId=12) and the combo boxes must be prepopulated with these values - ie. florida and miami.
At the moment it seems to be doing this to some extent with code provided.

The problem is that when I change the Region selection after it has been prepoulated, the second combo does not reload. It still only shows the old values. In other words a new call to repopulate the town combo is not being made.

My question is, how do I get the second dropdown to make a new call and reload the info based on the new region selection?

This problem ONLY occurs when the combo values are preset (eg. pagename.aspx?regionId=10&townId=12) , and not when you come to the page for the first time and select a region and then a town.

I suspect that this has something to do with the fact that these values were preset from the server side, and that this does not fire the call that needs to be made :

ddnRegion.SelectedIndex = ddnRegion.Items.IndexOf(ddnRegion.Items.FindItemByValue(Request.QueryString["region"]));  
 
ddnTown.SelectedIndex = ddnTown.Items.IndexOf(ddnTown.Items.FindItemByValue(Request.QueryString["town"]));  

0
Yana
Telerik team
answered on 17 Feb 2009, 01:26 PM
Hi Carlo,

I am still not able to replicate this issue at our side, please check my test page I've attached for a reference. I opened the url like this: "comboBoxProblem.aspx?region=1&town=3"  and it works without a problem.

Regards,
Yana
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
Tags
ComboBox
Asked by
Carlo
Top achievements
Rank 1
Answers by
Yana
Telerik team
Carlo
Top achievements
Rank 1
Share this question
or