Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

swap one control for another?

Status
Not open for further replies.

MrPeds

Programmer
Jan 7, 2003
219
0
0
GB
Hi,

I have a simple web form written in vb.net that allows you to edit some information. (The back end is SQL Server) and i am using Visual studio 2003.

at the moment, you select a value from a drop down list and the corresponding fields are populated with values based upon teh selection. This works fine for an edit or a delete.

however, I would like to know if it is possible to swap the drop down menu for a standard text field when i add a new record to the database. i.e. when i click 'Add new record' the form posts back on itself and the drop down is replaced by the text field, and the other text boxes are blank.

I know i can do it by copying the said form and creating a new one but it seems like overkill for one control.

any suggestions on what techniques or clever approaches can allow me to do this? i think that if i was doing this in Access I could simply type over the top of the drop down , but not sure if you can do this in a web control.

thanks in advance,

MrPeds
 
you can have both controls on your form, and then initially set the textbox.visible= false.

when you click on 'Add new record', set the dropdownlist visibility to false and that of the textbox to true.
 
I have had to do this a number of times add, edit and delete db records. As you are I use a list to select particular records. For add I pop up a simple 1 textbox form in a modalDialog and immediately receive name (key) of new record - on OK this can then be posted back and varified to be unique before adding to db with default values and then presented to user as a normal record that can be edited. This allows error messages etc. if key already used.

Just some thoughts...

Gary
 
Use a PlaceHolder server control.

<asp:placeHolder id=&quot;plhText&quot; runat=&quot;server&quot;/>

Then change the control at the place holder dynamically according to the edit mode.

txtBox = new Textbox
txtBox.Text = &quot;Enter here&quot;
plhText.Controls.Add(txtBox)

 
thanks for this guys - I will post my code on here for other newbies in due course.

The placeholder method seems a lot cleaner than older version of ASP from what I can make out so far.

MrPeds.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top