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

[Solved] Multiple ComboBox Help!

5 Answers 193 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Henry
Top achievements
Rank 1
Henry asked on 17 Jun 2008, 12:41 AM
Hi I tried the sample code in for multiple comboxboxes.
My code is below. The problem is it does not load the 2nd boxes items.

This line:    LoadCountries(e.Text);

e.Text is always empty. Any ideas why?  That is why it's not loading up the next boxes items.



using System;
using System.Data;
using System.Data.OleDb;
using Telerik.WebControls;
using DBUtils;


    /// <summary>
    /// Summary description for _Default.
    /// </summary>
    public partial class DefaultCS : System.Web.UI.Page
    {




        private void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {
                LoadContinents();
            }
        }


        #region Web Form Designer generated code
        override protected void OnInit(EventArgs e)
        {
            //
            // CODEGEN: This call is required by the ASP.NET Web Form Designer.
            //
            InitializeComponent();
            base.OnInit(e);
        }

        ///        Required method for Designer support - do not modify
        ///        the contents of this method with the code editor.
        /// </summary>
        private void InitializeComponent()
        {
            this.RadComboBox1.ItemsRequested += new Telerik.WebControls.RadComboBoxItemsRequestedEventHandler(this.RadComboBox1_ItemsRequested);
            this.RadComboBox2.ItemsRequested += new Telerik.WebControls.RadComboBoxItemsRequestedEventHandler(this.RadComboBox2_ItemsRequested);
            this.RadComboBox3.ItemsRequested += new Telerik.WebControls.RadComboBoxItemsRequestedEventHandler(this.RadComboBox3_ItemsRequested);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion

        private void LoadContinents()
        {

            DataSet ds = DBHelper.GetRegionsForCombo();

            RadComboBox1.DataTextField = "Region";
            RadComboBox1.DataValueField = "Region";
            RadComboBox1.DataSource = ds;
            RadComboBox1.DataBind();

            foreach (RadComboBoxItem item in RadComboBox1.Items)
            {
                item.ToolTip = item.Text;
            }
        }

        private void LoadCountries(string region)
        {
            if (String.IsNullOrEmpty(region)) return;

            DataSet ds = DBHelper.GetPortsForCombo(region);

            RadComboBox2.DataTextField = "Port";
            RadComboBox2.DataValueField = "Port";
            RadComboBox2.DataSource = ds;
            RadComboBox2.DataBind();

            foreach (RadComboBoxItem item in RadComboBox2.Items)
            {
                item.ToolTip = item.Text;
            }
        }

        private void LoadCities(string port)
        {
            DataSet ds = DBHelper.GetFacilityForCombo(port);

            RadComboBox3.DataTextField = "Facility";
            RadComboBox3.DataValueField = "Facility";
            RadComboBox3.DataSource = ds;
            RadComboBox3.DataBind();

            foreach (RadComboBoxItem item in RadComboBox3.Items)
            {
                item.ToolTip = item.Text;
            }
        }

        private void RadComboBox1_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
            LoadContinents();
        }

        private void RadComboBox2_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
            LoadCountries(e.Text);
        }

        private void RadComboBox3_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
        {
            LoadCities(e.Text);
        }
    }

5 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 17 Jun 2008, 06:55 AM
Hi Henry,

Can you paste here the javascript function which handles OnClientSelectedIndexChanged event of the continents combobox?
I guess you invoke requestItems() of the countries combo in it.

Regards,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Henry
Top achievements
Rank 1
answered on 17 Jun 2008, 11:08 AM
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DefaultCS.aspx.cs" Inherits="DefaultCS" %>

<%@ Register Assembly="RadComboBox.Net2" Namespace="Telerik.WebControls" TagPrefix="rad" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <rad:radcombobox id="RadComboBox1" runat="server" autopostback="True" OnClientSelectedIndexChanged="LoadCountries"></rad:radcombobox>
        <rad:radcombobox id="RadComboBox2" runat="server" autopostback="True" OnClientItemsRequested="ItemsLoaded" OnClientSelectedIndexChanging="LoadCities"></rad:radcombobox>
        <rad:radcombobox id="RadComboBox3" runat="server" autopostback="True"  OnClientItemsRequested="ItemsLoaded"></rad:radcombobox>
    
    </div>
    
               <script type="text/javascript">

                var RadComboBox2 = <%= RadComboBox2.ClientID %>;    
                var RadComboBox3 = <%= RadComboBox3.ClientID %>;    

                function LoadCountries(item)
                {    
                    countriesCombo.SetText("Loading...");
                    citiesCombo.ClearSelection();
                    
                    if (item.Index > 0)
                    {        
                        countriesCombo.RequestItems(item.Value, false);                                
                    }
                    else
                    {
                     countriesCombo.Items = [];
                        countriesCombo.SetText(" ");
                        countriesCombo.ClearItems();
                        
                        citiesCombo.Items = [];
                        citiesCombo.SetText(" ");
                        citiesCombo.ClearItems();
                    }
                }

                function LoadCities(item)
                {    
                    citiesCombo.SetText("Loading...");
                    citiesCombo.RequestItems(item.Value, false);                    
                }
                
                function ItemsLoaded(combo)
                {
                    if (combo.Items.length > 0)
                    {
                        combo.SetText(combo.Items[0].Text);
                        combo.Items[0].Highlight();
                    }
                    combo.ShowDropDown();
                }

            </script>
    </form>
</body>
</html>
0
Veselin Vasilev
Telerik team
answered on 18 Jun 2008, 03:23 PM
Hello Henry,

The problem is that the javascript variables are named:
                var RadComboBox2 = <%= RadComboBox2.ClientID %>;    
                var RadComboBox3 = <%= RadComboBox3.ClientID %>; 
while you are using
countriesCombo and citiesCombo variables.

I suggest that you replace countriesCombo with
RadComboBox2 and citiesCombo with RadComboBox3 everywhere in the <script> section.

I hope this helps.

Sincerely yours,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Henry
Top achievements
Rank 1
answered on 18 Jun 2008, 03:39 PM
Hi ,

Ok, now it seems to pass the proper information via e.Text in the event.

The 2nd combo box now just has Loading, the items are being databound(see code above) ... but not being displayed.

Any Ideas?

Henry
0
Veselin Vasilev
Telerik team
answered on 23 Jun 2008, 12:31 PM
Hi Henry,

This is because you have AutoPostBack set to True.
I have created a sample page which demonstrates the approach in this scenario. Please download it and observe it.
I hope this helps.

Best wishes,
Veskoni
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
Tags
ComboBox
Asked by
Henry
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Henry
Top achievements
Rank 1
Share this question
or