Populating Combo Box based on other combo box

  1. #1

    Populating Combo Box based on other combo box

    I m using two Coolite combo boxes- cmbCountry and cmbStates.

    I've filled the cmbCountry with country names while page loads.
    I want to populate "cmbStates" with names of states of perticular country that is selected in cmbCountry.

    I am using all data from tables.
    Used cmbStates.Items.Add to add the states' names.

    Written the code to populate/add states in cmbStates in Change event of cmbCountry.
    I have used data table "mDtTbl" to fill values in both the comboboxes.

    if (mDtTbl.Rows.Count > 0)
                {
                    for (int i = 0; i <= mDtTbl.Rows.Count - 1; i++)
                    {
                        mCombo.Items.Add(mDtTbl.Rows[i][0].ToString());
                    }
                }
    CmbCountry is filled in and displaying country names properly.
    While debuging it shows that values are coming in cmbStates, but not displaying in.

    is there any setting needed like "postback" to get the work done?
    Any help..?
    Last edited by geoffrey.mcgill; Feb 21, 2011 at 10:13 PM.
  2. #2

    RE: Populating Combo Box based on other combo box

    Hi,

    You need use the Store instead combo's items. The items can't be updated during AjaxEvent. Just use combo's with store and rebind the store with new data during AjaxEvent
  3. #3

    RE: Populating Combo Box based on other combo box

    Hi Vladimir,

    Thanks for the prompt reply.

    As u have suggested, I have already tried using store to populate the cmbStates.

    Suggest your reply by example if possible.

    Also add if it is possible using ajax event fired when we change selection of cmbCountry

    like...

    protected void cmbCountry_Changed(object sender, AjaxEventArgs e)
    {
             //Some code to populate cmbState
    }
    Thanking you again!

    Help! Help!
    Last edited by geoffrey.mcgill; Feb 21, 2011 at 10:13 PM.
  4. #4

    RE: Populating Combo Box based on other combo box

    Hi,

    Just see the following example

    https://examples1.ext.net/#/Form/Com...Linked_Combos/

    It should be enough to accomplish what you need
    Last edited by geoffrey.mcgill; Feb 22, 2011 at 12:31 AM.
  5. #5

    RE: Populating Combo Box based on other combo box

    Thanks!

    It works..


    Expecting more help in future..

    Regards..

Similar Threads

  1. Combo box value
    By Kev in forum 1.x Help
    Replies: 7
    Last Post: Jun 15, 2012, 12:54 PM
  2. Replies: 8
    Last Post: Nov 28, 2011, 9:25 AM
  3. Replies: 6
    Last Post: Aug 25, 2011, 2:13 PM
  4. Binding ajax based combo from the code behind
    By verbatimbot in forum 1.x Help
    Replies: 0
    Last Post: Apr 06, 2011, 2:02 PM
  5. Replies: 3
    Last Post: May 11, 2010, 10:36 AM

Posting Permissions