Solved

2 dropdownlist bounded to each other

Posted on 2006-06-28
4
466 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 7

Accepted Solution

by:
osiris247 earned 500 total points
ID: 17029534
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
ID: 17029539
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
ID: 17029808
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
ID: 17030707
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…

726 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