0

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...

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by dnanetwork
0

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 :-)

0

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'.

0

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.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.