Click here to Skip to main content
15,074,987 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
In the panel there are 5 controls;
one is Date,
one is Location From,
one is Location To and
the last one is Total Cost. and one add button.

All the above controls are in a panel.
Location From, Location To these are drop-down menu and the values are come from DB. Total cost is generated as per the Drop-down value. These 3 fields are dynamic.

After selecting value from these control when add button is clicked all the values are inserted into DB and again the 5 controls are generated automatically below the previous control.

Now my question is i can do this when there is only 5 controls in the panel; how should i do in this case? the add button generate the 5 controls every time and the code behind the add button is written once;the 1st time add button works to insert value into DB but from the next time it will work as remove button as well as remove the controls also.

hope i can explain my view properly. if any confusion don't hesitate to ask.
you can also check this over here: Online Booking[^]
Posted
Comments
fct2004 31-Mar-12 21:58pm
   
That link doesn't really look like the thing you're talking about.
fct2004 31-Mar-12 22:04pm
   
Are trying to say that some of the controls are tied to an entity in your database, and you want to create more controls of the same types that are tied to a new entity when the button is clicked?
sahabiswarup 31-Mar-12 23:51pm
   
i want to create that type of dynamic control exactly implemented on that website; so please suggest me how to begin...

1 solution

The first thing I would do is design what it should look like once all the information has been filled in. When doing this, you might want to group controls that are expected to be filled in at the same time together.

I don't know if you are using WinForms, WPF, ASP.NET or what, but I can think of three general ways get the dynamic control fill-in that you want.

1. Create a control that hosts the controls you want to show up together. Then create and insert it into the UI container at run time.

2. Create a control that hosts the controls you want to show up together or host them in the same container, place the control or container in the UI. Collapse it (the control/container) it in the designer, and make it visible again when in code once the time is right.

3. Use a table or grid with collapsible rows or columns, that will also hide the contents of the rows or columns when collapsed. If this were WPF, I would use a Grid control, and I would either name the row/column definitions or bind the sizes of the row/column definitions. When it's time to show the controls, make the row/column visible to the user.

Method 1 will create controls dynamically, like you asked. Methods 2 and 3 will just make it look like you created the controls dynamically even though they're always there.
   

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