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

MultipleComboBoxes

2 Answers 71 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
dev79
Top achievements
Rank 1
dev79 asked on 16 Mar 2009, 05:34 PM
Hello,

I was able to successful run this demo: http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/multiplecomboboxes/defaultcs.aspx

However, in LoadCities function in the where clause I wanted to be able to pass 2 parameters instead of one.  For example, let's say I want to do the following, "SELECT * FROM Cities WHERE CountryID=@CountryID and ContinentID=@ContinentID".  Below is the function from the demo.

 

protected void LoadCities(string countryID)

 

{

 

SqlConnection connection = new SqlConnection(

 

 

ConfigurationManager.ConnectionStrings["TelerikConnectionString"].ConnectionString);

 

 

SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Cities WHERE CountryID=@CountryID", connection);

 

adapter.SelectCommand.Parameters.AddWithValue(

"@CountryID", countryID);

 

 

DataTable dt = new DataTable();

 

adapter.Fill(dt);

RadComboBox3.DataTextField =

"Name";

 

RadComboBox3.DataValueField =

"ID";

 

RadComboBox3.DataSource = dt;

RadComboBox3.DataBind();

 

foreach (RadComboBoxItem item in RadComboBox3.Items)

 

{

item.ToolTip = item.Text;

}

}

Thanks,
Ivy

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 17 Mar 2009, 12:02 PM
Hi,

Try with the following code snippet and see if it helps.

CS:
protected void LoadCities(string countryID,string continentID
 
 SqlConnection connection = new SqlConnection( ConfigurationManager.ConnectionStrings["TelerikConnectionString"].ConnectionString); 
 
 SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Cities WHERE CountryID=@CountryID And ContinentID=@ContinentID", connection); 
 
 adapter.SelectCommand.Parameters.AddWithValue("@CountryID", countryID); 
 adapter.SelectCommand.Parameters.AddWithValue("@ContinentID", continentID); 
 
  DataTable dt = new DataTable(); 
 
   adapter.Fill(dt); 
 
   RadComboBox3.DataTextField ="Name"
   RadComboBox3.DataValueField ="ID"
 
   RadComboBox3.DataSource = dt; 
   RadComboBox3.DataBind(); 
 
   foreach (RadComboBoxItem item in RadComboBox3.Items) 
   { 
 
    item.ToolTip = item.Text; 
 
   } 
 


Thanks
Shinu.
0
dev79
Top achievements
Rank 1
answered on 17 Mar 2009, 01:43 PM

Shinu,

 

Thanks a lot for replying.  It didn't work for me because I have another function that calls LoadCities, and only accepts one argument:

 

 

protected void RadComboBox3_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)

 

{

 

    LoadCities(e.Text);

 

}

If I change it to 2 arguments, it gives me an error. 

Any help is appreciated!

Thanks,
Ivy

Tags
ComboBox
Asked by
dev79
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
dev79
Top achievements
Rank 1
Share this question
or