Link to home
Start Free TrialLog in
Avatar of CoolDev2014
CoolDev2014

asked on

asp.net placeholder from db

i have table like

ID PlaceHolder    Desc
1   TextBox           VIN
2   Radio Button   Yes/No

In the frontend, I can query but I don't know how to dynamically create user control.
Like if it is textbox, it will create a textbox. I am thinking using Place Holder but I don't know how to implement that.

Let assume we already done the frontend, I need to find a way to capture data and save into the database. I can handle the SQL part but I don't know how to capture the data in a FOR loop.

Thanks, and see any experts can help.
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

I would personally add an asp:panel as a placeholder with nothing in it.

This shows the general setup:
http://forums.asp.net/t/1807044.aspx?Find+dynamically+added+controls+to+Panel+in+ASP+NET+using+C+

You can add each control (rather than just a label) based on the type.

Note you may want to add a parentControl to each control.
For instance:
  Your Radiobutton should be a radiobuttonlist  with a controlId
  then your radiobuttonlist should have the 2 radiobuttons (yes / no).  This way you can have other controls in there.

To iterate over the controls:

(foreach Control c in Panel1.Controls)
   //note that c. can have it's own controls, you'll need to loop through those as well.

the last piece is tying that to the DB . . . I usually recommend using some other attribute of the control (say tag for instance) to store the field.  You can then build your sql statements from that.

This is high level for now . . . if you need a clearer picture at the details feel free to ask.
Avatar of CoolDev2014
CoolDev2014

ASKER

Thank but hoping to get coding sample from my example.
What you're attempting to do is not a trivial thing.  It all depends on your architecture and how you've laid everything out.  Your question was how do you loop over each control in the place holder . . . that's done in the foreach loop.  What you do with it from there can vary on your requirements.

If you have specific questions relating to something in your code, I'd be happy to help.
ASKER CERTIFIED SOLUTION
Avatar of Manoj Patil
Manoj Patil
Flag of India image

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
Hey, Have you tried the above solution ?