How to populate a second dropdownlist using the value chosen in the first dropdownlist


I have a problem with 2 drop down list.  I dont' think I can use AJAX cascading drop-down-list because the two drop-down-list in my page do not have parent/child relationship.

Here's what I need to accomplish:

1.  First drop-down-list contains a list of Customer Code.  I can get this list using ObjectDataSource.

2.  After a Customer Code being chosen in the first field, can I pass that value to the second ObjectDataSource so it can use that value in a complex query to get the Customer Order?  

Is there any other way to accomplish this?

Thanks in advance!


6/25/2008 10:01:49 PM 93655 articles. 6 followers. Follow

4 Replies

Similar Articles

[PageSpeed] 27

This might help 


"Code, Beer and Music" that's my way of being a programmer!

How to get your Forum Question Answered | Blog | CodeASP.NET
6/25/2008 10:47:12 PM


Thanks for a quick reply.  After some thoughts, I think I have to make it clear that thos two DDLs are in DetailsView which using ObjectDataSource to populate the fields, and since those DDLs are in DetailsView, there are not an easy way to BindData to those DDLs.  I guess I probably will have to do the regular way, meaning not using DetailsView in order to BindData in each of the DropDownList.

If anyone knows how to have it working with two DDLs in DetailsView then I'd appreciate it greatly.  Thanks!


6/25/2008 11:10:38 PM

Hi qbui66,

Just look at the code u may get idea. I have not checked it yet but it should work.

Private Sub dtlView_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewCommandEventArgs) Handles dtlView.ItemCommand

Dim ddl As DropDownList = TryCast(sender, DropDownList)

If ddl IsNot Nothing Then

If ddl.ID = "Desired DDL" Then


End If

End If

End Sub

Please mark as Answer if it helps u. Thanks!

Parth Patel
Techsture Technologies
Software Developer
6/26/2008 5:09:07 AM

i think u should use a  hidden field to store customer code by using javascipt applied on first Dropdownlist.

And then while processing u should read customer code directly from Hidden field and fill records depending upon that in 2nd Dropdownlist.

Using javascript will also make this possible without any postback

6/26/2008 5:25:55 AM

Similar Artilces:

populate second dropdownlist based on value of first dropdownlist
 I have two dropdownlist contains countries and second states.i get the the countries and states from back end sql server 2005.after getting countries and states i put them in cache in global.asax and bind it to two dropdownlistsnow what i have to do is. my two dropdown's contains ALL.when i select ALL in countries dropdown i need to get all statesbut when i select certain country i should get only states belong to that country.So i have to apply row filter.all the countries and states are in the same dataset.can some one tell me how to do that.i can show you my co...

Two dropdownlists: first dropdownlist updates second via autopostback: Selecteditem.value always=1 for second dropdownlist
Hi All  This involves a form with 2 dropdown lists and other fields for user to fill.  dropdownlist 1 say countries of the world  dropdownlist 2 is cities in all the countries in the world when dropdownlist 1 is used to select a country, dropdownlist 2 is reloaded via autopostback event in list1 to show only cities in the selected country in list1, user can then select a city from list 2 and it would always match correct country. so far so good Problem: When I try to save the form to database, dropdownlist 1 gives me the correct value, but dropdownlist 2 always gives me...

Populate second DropDownList values based on first DropDownLists "SelectedValue" when FormView is in Edit Mode.
My FormView is getting its detail based on the selection in the Master Gridview control.The form subsequently loads its data, and when in edit mode it displays 2x DropDownLists. One is "Country", and the other is "State". Naturally the second DDL will depend on what the parent item is in the first DDL.I am hoping to find this so that I can preload the correct items in the 2nd DDL. I am hoping to accomplish this with as little code as possible, as I am using StronglyTyped DataSets and ObjectDataSource.cheers  try the following url, which is using AJAX

Update Second DropDownlist onSelectedIndexchanged of first Dropdownlist Using Atlas
   .I have 2 dropdownlists on ASp.NEt page one for Country and second for states. I want to update States DropDownlist onSelectedIndexchanged of Country Dropdownlist Using Atlas. I tried to implement this using Atlas July CTP. My query runs fine to retrieve records for the second Dropdownlist(checked Using profiler) while rendering the page it gives me Javascript Alert ("Unknown Error").I would appreciate your help to sort out this Problem ....My code sample is: <atlas:ScriptManager ID="ScriptManager1" EnablePartialRendering="true" runat="server">    ...

How to take selected value of dropdownlist in web method using cascading dropdownlist
Hi All,I am using C# 2.0 and ajax1.0.I am trying to fill dropdownlist using ajax cascading toolkit but I am not able to populate the dropdownlist.  My question is how do I take input value of parent dropdownlist in web service the fill the data that is in my senario I have subprod parent (fill on page load) and then Prod fill on subprod selection.  The web service method I used is  public CascadingDropDownNameValue[] GetProd(string knownCategoryValues, string category) { StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(known...

DropDownList selected value determines value of second DropDownList
I have a quick question that I'm sure has been addressed before, but I can't seem to find a solution. I have two drop down list fields: startTime and endTime coded as such: <asp:DropDownList id="startTime" runat="server"> <asp:ListItem Value="00:00">12:00 A.M.</asp:ListItem> <asp:ListItem Value="00:30">12:30 A.M.</asp:ListItem> <asp:ListItem Value="01:00">1:00 A.M.</asp:ListItem> <asp:ListItem Value="...

I have a DataGrid (see code at end of my question) with several dropdownlist controls within TemplateColumns for Editing.  For the first 2 ddls in my grid, ddlMedType and ddlMedicationName, I would like to populate ddlMedicationName based on the selecteditem of ddlMedType, but I don't know how to reference this. Thank you for saving me from confusion!!!! Here is my DataGrid code: NOTE: I've bolded the 2 controls that I need help with -- the rest you can really ignore!! ================== <asp:datagrid id="dgMeds" runat="server" OnEditCommand="dgMeds_EditRow" OnUpdateComm...

How to use the DropDownList to populate a Gridview using a second table?
Can I and if so, how do I add data to a table using a dropdownlist populated with data from a different table in any of the databound controls? I've tried to find specific documentation and have only been able to find a walkthrough that uses the table the DataGrid is bound to, which doesn't work for this issue. I am not sure if i understood your problem correctly.  But if you are looking for ways to copy Data table from source to other, it should be very simple DataTable mytab =ds.Tables["sample"].Copy (); where ds is a dataset already filled by an adapter. Not su...

How Select one dropdownlist value using down arrows corresponding other dropdownlist value are select
I am using two dropdownlist box.One is used for country selection. other one is used for state selection.I am using dropdown selectedindexchanged event. when i click country dropdownlist corresponding state is selected in state dropdownlist box. How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.R.Karthikeyan   kartmca: How select the country in country dropdownlist using down arrow keys at the same time corresponding state is select in state dropdown list.Generally, we don't implmenet...

Typing value in dropdownlist only uses first letter in value
If I have dropdownlist values, and start type something like: "Ascott", I hit the "A" values on the first letter, but then start way down at the "S" values on the second letter entry of "s".  So, when I hit "a", I go to "Abraham" in the list.  Now, if I hit "s", I'd like to be taken to "Ascott", but I'm taken all the way down to "Samuel" in the dropdownlist. How can I fix this? Thanks! i am not sure if you ca nchange this as this is the behaviour of the .NET controls ...... you can always use  the first letter to be take to first letter as you said but i never haerd of w...

populating a dropdownlist of states based on selection of country in dropdownlist and populating a dropdownlist of cities based on selection state in state dropdownlist
My code is this but i m not getting states in dropdownlist of states based on selection of country and  cities based on selection of state <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" ""> <html xmlns="" > <head runat="server"><title>Untitled Page</title> </head> <...

How to populate and use decided value of a DropdownList in ListView using VB, VS2008
I am tryiing to get a dropdownlist to work in a List View. What is the best source of a walkthrough for doing so.  I have googled a lot of sources, but using the advice of many hasnt' work.  Thanks. Hi JAYHAWKER, You can add a DataSource control such as SqlDataSource or ObjectDataSource to DropDownList in any Template in ListView, and then bind it to DropDownList in the same Template. Also you can bind a DataSet or DataTable to DropDownList by getting the reference of DropDownList In ListView. Thanks,Qin Dian TangMicrosoft Online Community SupportPlease remember to m...

Populate a dropdownlist using the SelectedItem property of another dropdownlist
 Hello everyone, I want to populate a dropDownList using an sql query that has the SelectedItem Property of another DropDownListFor instance, The first Dropdownlist has all Departments listed, when the user selects a deparment I want to query the data base and populate the second Dropdownlist with all courses in that department.Sort of something like: "SELECT CourseCode FROM Course WHERE CourseCode = DropdownList1.SelectedItem"Then I want to grab the results from the previous query and put it my second DropdownList. I know there are many articles on this out there, b...

Populate Dropdownlist using VB.NET
 Hi, Please help me,How can i populate a Dropdown list using code behind (VB.NET)??thanks JFRBPH12™  dropdownlist1.datasource = ds;dropdownlist1.datatextfield = "your display field";dropdownlist1.datavaluefield = "your value fieed"; dropdownlist.databind(); Give a man a fish and you feed him for a day. Teach a man to fish and you feed him forever. Hi  Try this sample :Partial Public Class Clock    Inherits System.Web.UI.Page    Protected Sub Page_Load(ByVal sender As Obje...

Web resources about - How to populate a second dropdownlist using the value chosen in the first dropdownlist -

Tag Synonyms - Stack Overflow
Q&A for professional and enthusiast programmers

Accidental entities - what about the UI?
This post is a follow-up to my previous blog post " Accidental entities - you don't need that identity ". In that post, we followed a consultant ...

Flash Builder Plug-in for SAP Netweaver Gateway - Adobe Labs
Search Navigation Labs Home Wiki Home Technologies Alchemy Blueprint Camera Profiles and DNG Profile Editor Cirrus ColdFusion 10 DNG Codec Fireworks ...

Air Astana - Join Now
Thank you for considering membership of Nomad Club – Kazakhstan’s first Frequent Flyer Program. You could soon be on your way to earning free ...

Languages -> C# Articles, Tutorials, Examples: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Blog - Avisra
Avisra Web Development Home Blog Services Contact The Blog Latest Module Builder: How can we make it better? Sitefinity by Chris on July 2, 2013 ...

Online Booking Tool Support
This Online Booking Tool Support page might help you as you navigate through the process of booking travel through your OBT provided by CWT. ...

@Html and beyond
... ); } return string .Format( “{0}{1}” , me.Member.Name, id); } The Html building methods are quite simple. Building a dropdownlist for a ...

Top Ranked Articles
Top Ranked Articles - Free source code and tutorials for Software developers and Architects.; Updated: 23 Feb 2013

Unit Testing DateTime.Now Without Isolation
public virtual void SeedWithYearsSince(DropDownList list, int year){ for (int index = year; index

Resources last updated: 12/19/2015 2:49:35 PM