?
Solved

2 dropdownlist bounded to each other

Posted on 2006-06-28
4
Medium Priority
?
486 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 1000 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Loops Section Overview
Suggested Courses

809 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