Last post Apr 29, 2011 01:56 AM by Decker Dong - MSFT
Apr 27, 2011 08:50 AM|mdoaie|LINK
I am having a 5 combo box in my from and each one has been bounded to the different table on the data base, every think works fine, but the problem is that I have used 5 data source to bound combo boxes.
If I use one data source for the entire combo boxes, it won’t work and obviously all of them will be show same value.
I would like instead of having 5 data source joust use 1.
I have tried to cleared the data source but it didn’t work and also clear combo box data source “combobox.datasource =null” but it dint work too.
Is there any solution to this problem?
Apr 27, 2011 11:00 AM|RaviSM|LINK
If could please explain more about your scenario. It will be more helpful for suggesting the solution.
Apr 27, 2011 01:45 PM|Team929|LINK
I think I understand your problem as I tried reasoning this as well in the past. Basically, you want a one shot trip to the database for all of your dropdowns instead of 5. I think you could tecnically accomplish this by having 10 columns, setting each dropdownlist
to look at 1 column for value and 1 column for visible. As for the practicality, I'm just not sure if this is the best idea although for this specific case, I'd call it potatos vs potahtos.
Apr 29, 2011 01:56 AM|Decker Dong - MSFT|LINK
I understand what you mean. However would you mind telling why you don't like 5 datasouces? They make your page slow? Or do something bad to you? Hehe……
Well, if you insist that you don't like, I think you should use SqlDataAdapter and use Fill to fetch 5 tables' data contents into the same DataSet. And then manually do binding like this:
using (SqlDataAdapter adapter = new SqlDataAdapter("select * from table1", new SqlConnection(……))
DataSet ds = new DataSet();
adapter.SelectCommand.CommandText = "select * from table2"; //Change your select statement for table2
Combobox1.DataSource = ds.Tables;
Combobox2.DataSource = ds.Tables;