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 missing something simple like having to set a relationship between the two adapters?

 

thanks in advance

0
JoeyCrack
10/31/2006 4:43:57 AM
asp.net.web-forms 93655 articles. 6 followers. Follow

2 Replies
991 Views

Similar Articles

[PageSpeed] 0

Suppose you have two DDL: ddl1 and ddl2, when you select from ddl1, you want to filter ddl2 ok?

<asp:DropDownList Id="ddl1" OnChange="FilterDDL('ddl1', 'ddl2');" ....></asp:DropDownList>

The above is the decleration of the first DDL. The second DDL is simple, just a normal DDL.

When the page loads, you populate both DDLs!

Now, the FilterDDL will be a JavaScript method as follows:

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="Testing.Bilal.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
	<HEAD>
		<title>WebForm1</title>
		<script>
			function FilterDDL(source, target) 
			{
				var ddlSource = document.getElementById(source);
				var ddlTarget = document.getElementById(target);

				// Get selected item in the source ddl
				var selectedVal;
				selectedVal = ddlSource.options[ddlSource.options.selectedIndex].text;
				
				if ((ddlSource != null) && (ddlTarget != null)) 
				{
					var index;
					for(index=0; index<ddlTarget.options.length;index++)
					{
						// if the selected value in source is equal to an item in the target ddl, remove it
						if (selectedVal == ddlTarget.options[index].value)
							ddlTarget.remove(index); // remove based on index
					}
				}
			}
		HEAD>
	<body>
		<form id="Form1" method="post" runat="server">
				<asp:DropDownList id="ddl1" runat="server" OnChange="FilterDDL('ddl1', 'ddl2');">
					<asp:ListItem Value="c#">c#</asp:ListItem>
					<asp:ListItem Value="asp.net">asp.net</asp:ListItem>
					<asp:ListItem Value="vb.net">vb.net</asp:ListItem>
				</asp:DropDownList>
				<asp:DropDownList id="ddl2" runat="server">
					<asp:ListItem Value="cobol">cobol</asp:ListItem>
					<asp:ListItem Value="asp.net">asp.net</asp:ListItem>
					<asp:ListItem Value="delphi">delphi</asp:ListItem>
				</asp:DropDownList>
		</form>
	</body>
</HTML>

 That was a sample page, that shows two DDLs, the idea is when you select a value from first ddl, the second DDL will be filtered in a sense, any value thatit contains that was selected in the first ddl, it will be removed.

The idea is just to show you how you control the DDL elements not more. So you have access for each option inside the DDL and for the text+value.

Use this code to customize it for your needs, hope this helps!

Regards


Bilal Hadiar, MCP, MCTS, MCPD, MCT
Microsoft MVP - Telerik MVP
0
haidar_bilal
10/31/2006 5:30:53 AM
If you've went thru the quickstart, you will find a good example using script callback There (to the buttom of page and see). Also, asp.net ajax's UpdatePanel will make this cascading dropdown quite a simple job.
你好! Just FYI o_O
0
Gordon
10/31/2006 7:20:17 AM
Reply:

Similar Artilces:

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

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    BindGrid() End If Here is my control (ddlCarManf) as is appears within grdCar in my .aspx page: <EditItemTemplate> <asp:dropdownlist id="ddlCarManf" AutoPostBack=true OnSelectedIndexChanged="PopulateCar" Runat="Server" Width="50px" />   </EditItemTemplate> 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.Thanks! Kevin Hi, klowery:You can get the ddlCarManf in the ...

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

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 code and demo http://www.asp.net/learn/ajax-control-toolkit/tutorial-15-cs.aspx     hope this will help youThanks And Regards,Manoj KarkeraZenith Software LTDPlease remember to click “Mark as Answer” on the post that helps you Use Ajax CascadingDropDownhttp://www.asp.net/ajax/ajaxcontroltoolkit/samples/Thanks & Regards,Kiran Bhadani (MCSD)Mark As Answer If my reply helped you.  Fill TextBox2 Items in SelectedIndexChanged Event of TextBox1 from SelectedValue.http://developerassistant.blogspot.com...

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

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

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

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 working okay so far, I have a Web Service that takes in a context key, based on this context key then goes off to the data access layer and pulls back whatever results I asked it to, all fine so far.  The dropdown list populates with the relevant values and I am able to select a particluar item from the dropdown list without any postback issues etc, I am also able to grab the selected value when doing a postback or where I have some javascript/ajax function that is trying to workout if the user has selected something. This particular user control also gets populated (has several fields) when a querystring is passed to the page it populates the fields during the page load (so my Page_Load method checks for this and goes off and grabs some values from a bunch of public properties to populate the user control controls). The problem I am having is not being able to change ...

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

Load Text box of one web form with selected list item of list box of another web form
one help please Problem is i have two web forms  1.  ForiegnkeyTest.aspx  2. foroginkeytable.aspx   step 1 1 ForiegnkeyTest.aspx one web form <head runat="server"><script language="javascript" type="text/javascript">   function popWin()   {         var confirmWin = null;      confirmWin = window.open('foroginkeytable.aspx','anycontent',   'width=455,height=435,status');   }  </script>     <        &nbsp;<asp:TextBox ID="txtaeropuerto" runat="server" CssClass="txtBox" MaxLength="3" Width="85px"></asp:TextBox></div>        <br />        <br />        <input type="button" onClick="popWin()" value="Open Window">   step2 . foroginkeytable.aspx ( tiena una listbox cargando sobre base de datos <div>        <asp:DropDownList ID="txtciudad" runat="server" CssClass="dropdown" DataSourceID="SqlDataSourceCIUDAD"            DataTextField="CIUDAD" Da...

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 but also with no luck. Suggestions anyone...? The Method will be like this1. You will rise a selectedindexchanges method for the firstdropdownlist.2. when event fires,in the code  for(int vLoop=0 ; vLoop<gridview1.rpws.count ; vLoop++) {  Dropdownlist ddl1 = gridview1.rows[vloop].findcontrol("dropdownlist1") // here dropdownlist1 is the id of the dropdownlist that you have given in itemtemplate  if(ddl1=(dropdownlist)sender)  {   Dropdownlist ddl2 = gridview1.rows[vloop].findcontrol("dropdownlist2") // here dropdownlist2 is the id of the dropdownlist that you have given in itemtemplate     // Now do your database manipulations   }  }  Here in this method, check whether ddl1,ddl2 are nulls or not.if they are nulls, that means, you are giving the name providingi...

Using a selection from a dropdown list to fill in a second dropdown list.
Hi,  I am new to the web programming area and looking for some help.  I have a situation where, like i said in my subject trying to base the list in the ddl2, to be based on the selection from ddl1.  What do i all need to include to do this.  As of now, I have two seperate SQL data sources, with the first one I have it just selecting from our database.  For the second list, I have a second sql data source that does a selection of a different column from teh same database but in the where clause have a parameter that will equal the selection from teh first.. &n...

Problem with 2 dropdown lists (second dropdown list reset automatically)
My Question is pretty simple.I have two dropdown lists. Once I clicked on one then second one gets populated (through SelectedIndexChanged and with AutoPostBack = true) now I am selecting the value in the second dropdown list and then hitting submit button. I am now sending these values to another page. but hte value in second drop downlist is always selected the first value (though i have selected the item other than first one)I am loading first dropdownlist in page load and under (if (!IsPostBack){ } )This is very silly things happening any bdoy has any idea about this or faced the same pr...

can i drag the selected value of dropdown list in one web part to another web part
hi, supose i am having time displaying in on webpart can i drag the value of time to another web part and and display the time is: and the value draged from the other webpart so i want to drag the value year and population into antoher web part and according to that the grap must appear i.e what  i exactly want is i must drag some value from one webpart to onother webpart and according to event some thing must happen in another web part   Hi, The problem has been replied in the following post: http://forums.asp.net/t/1141884.aspx But from the title you described, do ...

Select Country From Dropdown list and Show its City Automatically in Dropdown, Hows?
Hi, em new in VB.NET kindly solve my problem its urgent.i want to show two dropdown menu in which one for country and secound is for city.when user select country its cities automatic populate in other drop down. just like in Hotmail, Yahoo email form. but remember i bound the values of dropdown from the database. means values of dropdown must be extract from the database.  Use the ASP.NET AJAX Cascading Dropdown.  There is also a tutorial on how to use it with a database.Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you!  ...

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

Display diff content in middle of Web form based on Radio button list selection
Hello, I have a need to display an image and a table (with ButtonList and Label inside this table) in the middle of my web form based on user selection from a radio button list (which has 6 options).  I can write a dynamic population of the image, label, and button list based on user selection but wonder if there is other methods; for examples 6 static panels already set up in the web page and swap it in using multiview or etc.. Looking for best opion from expert of this forum. Appreciates for help/tips Regards, Hn.  There is a number of ways to achieve that.I would not go w...

Stuck trying to automatically populate three text fields based on value selected in gridview dropdown list
Hello, When I click on the gridview edit button and select a value from the ComponentID DropDown list I would like fields, tbxFunctions, tbxFuncFail, and tbxFailMode to be updated with the information that matched the ComponentID from tblFailures: Question 1) do I need to create an object data source or sql data source to get functions, funcFail, and failMode by ComponentID Question 2) Not Sure how to set the text property to for tbxFunctions, tbxFuncFail, and tbxFailMode.  Do I add a Select Parameter statement below?  <SelectParameters> <as...

dropdown should only be visible based on a selection in another dropdown
I'm using VS2003. I have two dropdowns.  One should become only visible if a specific item is selected in another dropdown.dropdown1 - always visible, if A is selected thendropdown2 should be visibleI have this logic in the code behind:private void dropdown1_selectedindexchanged(object sender, system.eventargs e){if dropdown1.selectedvalue.equals("A"))lable2.visible=true;dropdown2.visible = true;} This doesn't work though.  dropdown2 and it's label are always visible.  When I set both to visible false, then they are always not visible. Set the &qu...

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

How to combind two dropdown list values into one dropdown list?
Hi All, I refered some websites, they are combinding two dropdown list values into single, but i don't know .Net will support it or not? If any body knows it plz tell me how to achieve it?? EX: Go to Naukri.com and select Functional Area dropdown list there u can see main & sub category names in one dropdown list!!!   Thanks, Aswath.  hi just concatenate , or - for ex:Dropdownlist1.Datatextfield= maincategory & "," & Subcategory Regards,M.VenkatesanMy Blog : http://venkat-dotnetsamples.blogspot.comPlease remember to click “Mark as Answer” on the pos...

Populating and Implementing 4 Dropdown lists on web form through web service
Hi all, I have a Project due after one week. It is a web service project. I have a Web Form which communicates to the web service and this web service communicates to the database. I have all my SQL statements in the Data Acess Layer to create more secure web service application. The Web service class is also in the Data Access Layer. I need to populates the 4 Dropdown list boxes on the web form from one table. I have Customer table which contains information About CustomerName, CustomerType, Address, City. These 4 colum values should populate the 4 Dropdown lists. And then I need to implem...

ajax + update panel + dropdown list + trigger = dropdown list flashing
Hi,I have a dropdown list inside an ajax update panel, have the trigger to refresh every 2 seconds, all works great except the dropdown list refreshes every 2 seconds and visually it doesn't look right (the whole drop down box flashes), how do i set it so the dropdown box doesn't flash every 2 seconds? TIA   does it have something to do with binding the control on the trigger? Hi Joey_Crack, Would you please post the simple sample which contains your issue?  So we can troubleshoot in your shoes.  I have made a simple sample based on your descri...

Web resources about - automatically generating content in a dropdown list based on the selection of another dropdown list - asp.net.web-forms

Piccolo Automatically Sends Users Prints Of Their Photos On Facebook, Instagram
... a popular day for debuting Instagram applications and services, as startup Piccolo announced its beta launch, aimed at allowing users to automatically ...

Facebook Status Update Tagging Now Automatically Suggests Matches for People, Pages and Other Content ...
Facebook has just changed its status update tagging tool to automatically display a drop-down menu of friends, Pages, events and groups you might ...

Meekan - schedule meetings and events automatically on the App Store on iTunes
Get Meekan - schedule meetings and events automatically on the App Store. See screenshots and ratings, and read customer reviews.

Does Google see automatically generated content as a bad thing? - YouTube
Does Google see automatically generated content as a bad thing (i.e. spam)? If I publish uncopyrighted content on my site that is available from ...

Lesbian mothers to be automatically recognised on birth certificates in SA - AdelaideNow Search Search ...
BOTH lesbian mothers will be recognised on their child’s birth certificate — not just the woman who gives birth — under changes approved by Parliament’s ...

Skippa TV recorder to automatically skip the ad breaks
No stranger to controversy, Australia's IceTV is preparing another challenge to the power of Australia's free-to-air broadcasters.

This bed automatically makes itself three seconds after you get up
Meet the OHEA smart bed. The OHEA smart bed automatically makes itself just three seconds after you get up. In 50 seconds, it straightens your ...

Emailing porn at work not automatically sackable, court finds
Australia's federal court has upheld a ruling that emailing pornography in the workplace is not automatically a sackable offence.

Shazam iPhone app now listens for music, TV shows automatically
Shazam has updated its iPhone app to tag songs, TV shows and more on its own, no longer requiring users to open the app and tap a button.

App of the day: Human for iPhone automatically tracks your movements
Human for the iPhone is an activity tracker that automatically distinguishes between different types of movement.

Resources last updated: 3/24/2016 7:18:41 PM