Populate dropdown list based on selected value in another dropdown list

I have a datagrid (grdCar) that contains two dropdown listboxes (ddlCarManf and ddlCar). When the user clicks the "Edit" link and places the grid into edit mode, they select a value in ddlCarManf. Based on the selected value in ddlCarManf, I need to then populate ddlCar with a list of cars for which the selected manufacturer makes (I'm using ddlCarManf.SelectedValue to query the database).

 I bind my datagrid in the page_load event as:

If Not Page.IsPostBack Then



End If

Here is my control (ddlCarManf) as is appears within grdCar in my .aspx page:


<asp:dropdownlist id="ddlCarManf" AutoPostBack=true OnSelectedIndexChanged="PopulateCar" Runat="Server" Width="50px" />



My thought is to populate ddlCar in the PopluateCar sub-procedure, but when the selected index changes and PopulateCar is called, I can't seem to find either control (ddlCar or ddlCarManf) from within the PopulateCar sub-procedure. I know I can find controls from within a datagrid event, but this is not the case in this example.

Would anybody be able to help me understand how to populate a dropdown listbox, based on the selected value from another dropdown listbox, both of which are located within a datagrid? I may attacking this in the wrong way and I'm open for any suggestions.



5/20/2007 7:09:56 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 42
Get it on Google Play
Get it on Apple App Store

Hi, klowery:
You can get the ddlCarManf in the PopulateCar function by
DropDownList dp = (DropDownList)sender;

There are two ways to get another DropDownList control
DataGridItem editItem = dg.Items[dg.EditItemIndex]; 
DropDownList dp2 = (DropDownList)item.FindControl("ddlCar");OrTableCell cell = (TableCell)dp.Parent; 
DataGridItem item = (DataGridItem)cell.Parent;
DropDownList dp2 = (DropDownList) item.FindControl("ddlCar ");

Next,get datasource according to dp.SelectedValue

cnn = new SqlConnection(); cnn.ConnectionString = ConfigurationManager.ConnectionStrings["st"].ConnectionString; cnn.Open(); 
SqlCommand cmm = new SqlCommand();
cmm.Connection = cnn;
cmm.CommandText = "select car from catTable where man='" + dp.SelectedValue + "'";
SqlDataReader reader = cmm.ExecuteReader();
dp2.DataSource = reader;

This is just an example, you can change the code according to your project.
Hope it helps.


Techie Zhang
Microsoft Online Community Support
5/21/2007 3:37:17 AM

Thanks for your response!

 I apologize for not repsonding to your post sooner, but I have been put on another project and I have not had any time to fix this issue. I hope to get to it this weekend :)

I will let you know what I discover.



5/30/2007 12:12:00 AM

Similar Artilces:

Populate a Dropdown List based on the value of another Dropdown List
 Hi ALL,    I have two Dropdown List.I need to Populate second Dropdown List based on the value of first Dropdown List.I am n't using Update Panel.Pls suggest me RegardsSri ASP.NET AJAX Cascading DropdownDarrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you!   just populate second dropdown in SelectedIndexChanged event of the first dropdown. Muhammad ShoaibSoftware Engineer,Lahore, Pakistanwww.heartofpakistan.com (U/C)--------------------------------Mark it as ANSWER if it Helps U   Check out this link with co...

Filling a dropdown list, based on a selection from another dropdown list
This seemed like a simple venture, and may be, but with my limited asp.net knowledge, I am having a problem... Basically, I have a page that is gathering information. I want a user to be able to select a value from a dropdown list... On Auto postback I would like to make a second listbox visible and bind data to it based on the selection from the first. (While keeping the value of the first listbox available) Right now I am filling my dataset with the tables used in the page load event and setting my second listbox.visible to false. in the SelectedIndex_change event of the first...

automatically generating content in a dropdown list based on the selection of another dropdown list
hi i currently have a "categories" dropdown list i'm using to help filter data in a datagrid (have it setup using data and table adapters). i've introduced another dropdown list (called subcategories) to filter the datagrid so it only displays records that fit in both the category and subcategories.it all works fine, but i'm wanting to set it so the subcategories dropdown list gets generated on the client-side depending on the category selected. does anybody have any quick tutorials or a quick explination on how i could do this? am i missin...

Cascading Dropdown List
Hi, First post so hello and need some help with an issue I have been dealing with.  I have an intranet page I created in ASP.NET using C# .NET 3.5 with a few Ajax Extenders including 3 Cascading Dropdown Lists. Now I have used the Cascading dropdown lists for my own purposes i.e they do not actually cascade their results to another dropdown list, the reason I did this was due to the having a User Control that contains an update panel and other bits i.e I didn't want the control/page posting page (something that happens when you click on a regular dropdown list). Everything is wor...

Hide dropdown list based on other dropdown list selection
Hi, i have an aspx page with a form. I want to hide dropdown list b depending on what is selected for dropdown list a. I need to do this client side Im new to this so any assistance would be appreciated. Thanks in advance   could you explai briefly about your requirements? you want to maske dropdownlist b as invisible if you select any item on dropdownlist a? or you want to make it invisible for a specific item?   Hi,     Change the visibility of dropdownlist as false on selected index change. Private Sub ddl_a_SelectedIndexChanged(ByVal sender As Syste...

Can I populate a Dropdown list in a GridView from another Dropdown list
Hi there, I have a Gridview control that contains 2 DDLs. The first one is populated on page load (from a Generic list in the code behind) and is working with no problems. I want to populate the 2nd DDL by making a selection in the first DDL which in turn would call a DB method and cause a postback. I've tried using the "OnSelectedIndexChanged" method for the DDL and the "FindControl" method for the 2nd DDL, but the GridView can't find it on Postback and throws an error. I've also tried using the "onSelectedIndexChanged" method for the GridView bu...

one dropdown list affecting another dropdown list vb.net
I am desgining a website using VB.NET wherein the data items of one dropdown list depends on the selection of a data item in the previous dropdown list something similar to selection of country USA from 1st dropdown list...triggers 2nd dropdown with list of states in USA How can this be accomplished.... Any help will be appreciated... Thanks & Best Regards... hi boy,first I suggest turn on auto postback on first dropdownlist. In select index changes(first dropdownlist) - select value on second dropdownlist My blog is here.Please remember to 'Mark as Answer' i...

Selection in one dropdown list effecting the visibility of another dropdown list
I have two drop down lists. They are not databound. We'll called them dropdownlist1 and dropdownlist2.Basicly, I want people to choose an object in the first dropdownlist. Depending on their selection, it will make certain items in dropdownlist2 invisible.Currently my thought is to have something in the lines of the following (In the dropdownlist1 - SelectedIndexChanged - Postback being set to Auto)if dropdownlist1.text = "Such and such" then(this is where I would declare which options are available)However, I do not know the proper syntax of saying make the following item...

Filter dropdown list from another dropdown list
Help Please!!! I am trying to filter the data in a dropdown list from information chosen in another dropdown list. 1st table has modification types, 2nd table has modifications. When the user chooses the modification type needed, then only those modifications should appear in the 2nd list. mydata7 = New SqlDataAdapter("Select * from ModificationList ", myconnection) ds7 = New DataSet mydata7.Fill(ds7, "table") Dim dr7 As DataRow ddlModification.Items.Add("Please select Modification ...") ...

Dropdown list bound to another dropdown list
I have two dropdown lists on my page. The first contains a list of names and the second contains a list of hardware devices. My problem is: When i choose a name from the first dropdown i need the second to become populated with their related devices. This works fine, however if i then change the name in the first dropdown list, it adds another set of devices to the devices dropdown list. The way i want it to work is to refresh the devices dropdown when the name is changed. So that only that persons related devices show up (in the second dropdown)  Any help would be much apprecia...

populate a dropdown list on the basis of other dropdown list
I need to populate a dropdown list on the basis of other dropdown list. Both dropdwon list are datasourced with SQL datasource. I tried the SQL datasource where query . but it will need a post back. I dont want my form to be postback. I guess this is what AJAX is for but i really dont know how to get this with AJAX in a simple and quick way..... or it is not simple and quick ????Mark as answer if anybody's post has helped you It can be simple and quick.  See this video:http://www.asp.net/learn/ajax-videos/video-77.aspx And also the tutorial on how to use the Cascading Dropdow...

How do I populate a dropdown list based on a selection of another dropdownlist on the same page.
Trying to figure out how to populate one dropdown list based on the selection of another drop down list.  Back in the old days, I would have passed the user between two pages. But, I have a list of Offices, based on a stored procedure that gets all the OfficeNames, and OfficeIDs.  I then have another drop down box of Employees, and based on which office you picked, I only want to display employees that work in that office.    How do I pass a value from the first drop down into the stored procedure to populate the second drop down.  (And, then because I know th...

Populating dropdown list based on dropdownlist selected value on gridview edititemtemplate
I have 2 dropdown lists in a gridview. While editing the grid I want to populate the EditTask dropdownlist based on the selected item value of the EditProject dropdownlist. I have functions to populate both dropdown lists in the code behind.I have created an event DropDown_SelectedIndexChanged which will fire on changing the project dropdownlist but can't find a way to populate the tasks based on the selected project.   Can anyone help please?    <asp:TemplateField HeaderText="Project" ItemStyle-VerticalAlign="Top&q...

How to get value from first dropdown list to second dropdown list
Hi Does soneone know hot to get value from first dropdown list to second dropdown list or remove it from seond dropdown list? I have a web form page. On the page, there are two dropdown lists, one Add button, and one Remove button . First dropdown list has four list items. Second one does not have list item yet. When select a item from first dropdown list, then click "add" button. I want it to apear in the second dropdown list without reload the page. Or select item from second dropdown list, and click "Remove" button. it will remove from second list. Please help. &nb...

Web resources about - Populate dropdown list based on selected value in another dropdown list - asp.net.presentation-controls

Facebook Fans Populate National Car Rental Playlist
... its Facebook fans are listening to, so the company teamed up with music-streaming service Songza to allow users who like its page to help populate ...

MySpace’s “Mashup with Facebook” Ports Likes to Populate Its Stream
... to Myspace to “create a personalized stream of entertainment content.” By offering new users signing up through Facebook Connect a way to populate ...

Perish the populate thought
Population size and growth, resources and climate change are obviously linked.

Islamic State militants raping thousands of women to populate caliphate, Iraqi official claims
ISLAMIC State fighters are reportedly raping thousands of women in Iraq and Syria to mass-produce spawn who&#8217;ll follow in their footsteps. ...

Researchers craft bot to populate Wikipedia with gene data
In order to help make Wikipedia a better source of information for biologists …

Are Chuck Schumer and Steve Israel Working To Populate Congress In The Image Of Scoop Jackson?
History lesson: In 1972 and again in 1976, the Beltway's conservative Democratic Establishment had found its man. The preferred candidate of ...

Extreme Shrimps Could Possibly be Sent to Populate Europa, NASA Reports
Rimicaris hybisae live on the edges of hydrothermal vents 7,500 feet underwater whose temperatures reach 750 degrees Fahrenheit.

Glowing robotic tentacles populate this Petting Zoo
(Credit: Minimaforms) If you swing by the Petting Zoo in Orleans, France, don't expect to see goats. The robotic "pets" that reside there hang ...

CNN.com - Millionaires populate U.S. Senate - Jun. 13, 2003
The U.S. Senate showed once more why it's sometimes called the millionaires' club.

Pokémon 2DS bundles soon to populate Australian store shelves
Australian gamers who have yet to pick up Pokémon X and Pokémon Y will be able to purchase one of two new Nintendo 2DS system bundles on June ...

Resources last updated: 2/5/2016 2:48:17 PM