Solved

2 dropdownlist bounded to each other

Posted on 2006-06-28
4
404 Views
Last Modified: 2012-05-05
In ASP.NET 2.0 I have a page with a formview in EditMode and in it 2 dropdownlist that one is a controll paramete
for the other. One is Country and it is a parameter for  the second. I can't make the second dropdownlist a bound field because if I do it when I change the country in the country dropdown list I get an error. How to deal with a situation like
this. Can the second Dropdoenlist be bounded? withe a BInd value?
Thank you.
I hope to get answer soon because lately I don't.
Anat
0
Comment
Question by:ANAT2403
  • 3
4 Comments
 
LVL 7

Accepted Solution

by:
osiris247 earned 500 total points
Comment Utility
Hi Anat.

I sometimes get similar problems when having a cascading style drop down binding scenario.

What i do is to bind to the first drop down as you have.  Then instead of setting the binding on the second drop down using the wizards, do it manually in the index changed event....
protected void ddlOne_SelectedIndexChanged(object sender, EventArgs e)
{
if (ddlDivision.SelectedIndex > 0) {
            //instance of table adapter....
            dsAreaStructureTableAdapters.CLE_RetrieveAreaByIdDivisionTableAdapter ta = new             dsAreaStructureTableAdapters.CLE_RetrieveAreaByIdDivisionTableAdapter();

            // This is if you want to add 'All' to the top of the dropdowns items.
            this.ddlTwo.Items.Clear();
            this.ddlTwo.Items.Add("All");
            this.ddlTwo.AppendDataBoundItems = true;
            this.ddlTwo.DataTextField = "NameField"; // Set the field names to bind to the correct fields on the drop down.
            this.ddlTwo.DataValueField = "IdField";
            this.ddlTwo.DataSource = ta.GetData(int.Parse(ddlOne.SelectedValue)); // get the data from the table adapter using the selected value from ddlOne
            this.ddlTwo.DataBind(); //Finally bind the data
        }
}

Hope this helps.

Steve
0
 
LVL 7

Expert Comment

by:osiris247
Comment Utility
Forgot to change the names of the table adapters to something generic........this code i c & p'ed from my own.

should be something like.... TableAdapterClass.TableAdapterName ta = new TableAdapterClass.TableAdapterName;

Steve
0
 

Author Comment

by:ANAT2403
Comment Utility
Hi,
OK first I wanted to be sure that the second dropdownlist has to be treated manually and I see that it is so.
I did it maually but in a different way . I used  hiddenfields to keep values after the selectedindexchanged
and also in loading.
Anat
0
 
LVL 7

Expert Comment

by:osiris247
Comment Utility
OK, i am not sure what if anything you are asking here?  Maybe its just my Monday morning, gutted about the football thing!!! :)

Steve
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now