Link to home
Start Free TrialLog in
Avatar of Sha_Sha_In
Sha_Sha_InFlag for India

asked on

Multiple Dependent Dynamic Dropdownlist Creation

Hi All,

I have an ASP.NET page in which I want to generate an input form dynamically which can contain 'n' number of input rows based on ID provieded by user. So that user can select\fill data on these rows and click on submit to save multiple data in one time.

I am successfully created these input rows with dynamic controls. The problem is that, each row contain two dropdownlist which are dependent on each other i.e. I want to bound second dropdownlist based on the selected value in first dropdownlist. These will be needed in each row.

Please provide me the right approach/solution to follow.
Language: C# ASP.NET
Avatar of maXXXeE
maXXXeE

use OnSelectedIndexChanged event

<asp:DropdownList ID="d1" runat="server" OnSelectedIndexChanged="d1_OnSelectedIndexChanged"...

codebehind:
protected void OnSelectedIndexChanged(object sender,EventArgs e)
{
      d2.SelectedValue="value to be selected"; //d2 is second dropdown

..........
........
Avatar of Sha_Sha_In

ASKER

Hi,

The given solution is well obvious, if you know the control's id as in case of static control. But in my case, the number of controls are dynamic, their id's are dynamically assigned and you have to find out the id of control before each operation. Ok, let me redefine problem,
----------------------
WEB FORM START
----------------------
[Order ID Text Box]                       [Add Controls Button]

Item1       [Input1 Drop Down List]       [Input2 Drop Down List]       [Input3 Text Box]      
Item2       [Input1 Drop Down List]       [Input2 Drop Down List]       [Input3 Text Box]      
Item3       [Input1 Drop Down List]       [Input2 Drop Down List]       [Input3 Text Box]      
.........
.........
ItemN       [Input1 Drop Down List]       [Input2 Drop Down List]       [Input3 Text Box]  

[Submit Button]
-----------------------
WEB FORM CLOSE
-----------------------

Problem:
----------
Here, when user give 'Order ID' and click on 'Add Controls Button', 'N' number of input 'Item' controls are dynamically generated and Id's are assigned to them. Here, when creating controls dynamically, 'Input1 Drop Down List' & 'Input2 Drop Down List' are bound with some values from dataset.

Now I want, when user filling the details against these 'Items' and when selecting 'Input1 Drop Down List', the associated value in 'Input2 Drop Down List' should be automatically selected which can however user change to another value as well. And finally click on 'Submit' to save 'Items' details.

What I am doing right now for problem:
-------------------------------------------------
When creating dynamic controls, I am associating each dynamic dropdown control with 'SelectedIndexChanged' event and making 'true' value of 'autopostback' property of each dynamic dropdown control. Then in the 'SelectedIndexChanged' event, I am finding 'Input1 Drop Down List' of which 'Item' raised the event and then trying to select associated value in same 'Items' 'Input2 Drop Down List'. But it is not happening. When debugging, it is showing Index to always Zero.

??? What can be the issue ???

Thanks In Advance!!!

SOLUTION
Avatar of maXXXeE
maXXXeE

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi all
Here is a javascript function which make multiple select boxes dependent or cascading easily.
This function uses jQuery for it's operations.
http://www.ajaxray.com/blog/2007/11/08/jquery-controlled-dependent-or-cascading-select-list-2/