Solved

2 dropdownlist bounded to each other

Posted on 2006-06-28
4
453 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
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

Technology Partners: 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

This article discusses the ASP.NET AJAX ModalPopupExtender control. In this article we will show how to use the ModalPopupExtender control, how to display/show/call the ASP.NET AJAX ModalPopupExtender control from javascript, how to show/display/cal…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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