Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi Friends,

need a help regarding an assignment. An .aspx page with a static textbox and a button named "Generate". we have to enter a number in the textbox (say 4) then on the Generate button click four(4) dynamic dropdownlist are created and a button named "ADD" is also created. The first dynamic dropdown contains number 1 to 10 and second dynamic dropdown contains 10 to 20 and so on... On clicking the dynamically generated button "ADD" button the selected values on the four dynamically created dropdownlist will added and shown in another dynamically created label and the dropdown should contain the selected values respectively without any javascript or jquery. basically its somewhat related to page lifecycle and viewstate. Can anybody please help?

Thanking You all friends. Looking for your kind help on the issue.
Posted
Updated 19-Sep-12 9:04am
v2
Comments
[no name] 19-Sep-12 14:25pm    
Okay and what specific issue are you having trouble with? What have you tried?
Sandeep Mewara 19-Sep-12 15:01pm    
It's a repost! I replied him today only.

You can definitely achieve this without using javascript or jquery. Here, the major problem is that you loose the dynamically created UI or the values on the post back of your "ADD" button click. The trick is to recreate your UI on postbacks.

1. Keep all your dynamic UI generation in one single method, say CreateDynamicUI()

2. In your CreateDynamicUI() ensure that you keep track of all the UI elements and assign unique IDs.

3. In-order to recreate UI on every postback, call CreateDynamicUI() in the Page_Load() of your aspx

4. In the "ADD" button click event, do a FindControl to get handles to the dynamically created elements.

I recommend to add all the dynamic content to one single parent control such as a panel or a table in-order to make the parsing easy.
 
Share this answer
 
Comments
Espen Harlinn 20-Sep-12 4:16am    
Good points :-D
I replied you today: http://www.codeproject.com/Messages/4371298/Re-Dynamic-Control-Help.aspx[^]

Why a repost? Did you try it? Please try and post specific issue.
Steps:
1. Define a GENERATE Button click handler X
2. In X, get the number provided in Textbox (say y)
3. Define a counter(say z). Set it to one.
4. Code a for loop from zero to y-1 (loop runs y times)
5. Create a dropdownlist inside the loop using new.

  • Provide ID
  • Define a datasource - a list
  • Populate list with fixed 10 numbers starting from z. for first loop z goes from 1 to 10, next 11-20...
  • Bind the datasource to dropdonw
  • Add the dropdown to the defined panel/placeholder in UI

6. Once for loop ends, create a button (A), define click event and add that too the defined panel/placeholder in UI.
7. for click event of A, do your manipulations as per need.

Try!
 
Share this answer
 
Comments
_Amy 19-Sep-12 15:44pm    
My +5! Good explanation. :)
Sandeep Mewara 19-Sep-12 16:34pm    
Thanks!
Espen Harlinn 20-Sep-12 4:15am    
5'ed!
Sandeep Mewara 20-Sep-12 4:54am    
Thanks.
Sandeep is already given the steps to create and manage Dynamic Asp.Net controls. If you need little more help or guideline while creating the controls then refer the links for similar articles:
Dynamically Created Controls in ASP.NET[^]
Working with Dynamically Created Controls[^]
Dynamically Created Controls in ASP.NET[^]
Creating ASP.NET Controls Dynamically[^]


--Amit
 
Share this answer
 
Comments
Espen Harlinn 20-Sep-12 4:16am    
Nice links :-D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900