I want to directly display list of contact name using drop down list when company name is selected from the company list in a drop down list in the same interface. I have no idea how to do this.

I am using C#.Net and SQL database.

I try to use SqlDataSource configuration using WHERE and Control. But, it didn't work. Please help me...

I want to directly display list of contact name using drop down list when company name is selected from the company list in a drop down list in the same interface. I have no idea how to do this.

I am using C#.Net and SQL database.

I try to use SqlDataSource configuration using WHERE and Control. But, it didn't work. Please help me...

AS per my understanding, You need to handle the SelectedIndexChanged event of Comapany name dropdown. In this event you need to fetch the data from database table related to Contact name for a selected Comapny name, then assign the data in data table and bind your contact name drop down with data table.
Also set the AutoPostBack = true to Company Name drop down.
It will work for you :-)

search for Binding Dropdownlist in google
you'll get the code snippets too...

AS per my understanding, You need to handle the SelectedIndexChanged event of Comapany name dropdown. In this event you need to fetch the data from database table related to Contact name for a selected Comapny name, then assign the data in data table and bind your contact name drop down with data table.
Also set the AutoPostBack = true to Company Name drop down.
It will work for you :-)

Actually, the drop down list for company name is displaying company name from company table. For the contact drop down list, i want to display it from the contact table where the company name for the contact is equal to value that is selected from the company name drop down list. I try to do C# coding for that. But, i got error. Actually, i don't know how to do it. But, i just try in error. Here, is my coding:

protected void CompanyList_SelectedIndexChanged(object sender, EventArgs e)
        {
            SQLConn = myDB.OpenDB();

            String companyName = CompanyList.SelectedItem.Value;

            String displayContact = "SELECT (contact_name) FROM Contact WHERE company_name = companyName";
            SqlCommand cmd = new SqlCommand(displayContact, SQLConn);
            int returnValue = cmd.ExecuteNonQuery();

            myDB.CloseDB();
        }

The error that occur at cmd.ExecuteNonQuery is:
Invalid column name 'companyName'.

that's a correct error..
you are not providing any parameter value to company_name

it should be company_name = ' "+your value which fits for company name+" '

hope that helps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.