Webboy2008
asked on
asp.net dynamic drop down
Experts,
I have a dropdown <select><option value=1>1</option><option value=25>25</option></sele ct>
When Onchange event is on, I would like to show like
City/State: <div><input name=city> <input name=state></div>
If 1 is selected, it show one city/state, if 25 is selected it show 25 city/state
and each <input name> has to be different.
And once the button is clicked, it will captures each city/state and save into the database.
Thanks
I have a dropdown <select><option value=1>1</option><option value=25>25</option></sele
When Onchange event is on, I would like to show like
City/State: <div><input name=city> <input name=state></div>
If 1 is selected, it show one city/state, if 25 is selected it show 25 city/state
and each <input name> has to be different.
And once the button is clicked, it will captures each city/state and save into the database.
Thanks
ASKER
strickdd: I think yours won't work to me. It just display <div> or not.
I need a list of city/state based on the number he/she select
Plus I need to save the value into Db as well.
Thanks
I need a list of city/state based on the number he/she select
Plus I need to save the value into Db as well.
Thanks
Then you can have you OnChange server event dynamically add the controls you need to a place holder. In that you can check the value and add the controls needed. The catch is, you will have to add these controls EVERY postback otherwise they will be lost. You can even have a method like this instead of you OnChange method:
protected void Page_Load(...)
{
if(Page.IsPostBack)
CreateFields();
}
private void CreateFields()
{
if(myDDL.SelectedValue == "1")
{
TextBox stateTextBox = new TextBox();
stateTextBox.ID = "MyTextBoxID" //This must be the same each postback
//Viewstate will automatically re-populate the textboxes when created like this
MyPlaceHolder.Controls.Add (stateText Box);
}
}
protected void Page_Load(...)
{
if(Page.IsPostBack)
CreateFields();
}
private void CreateFields()
{
if(myDDL.SelectedValue == "1")
{
TextBox stateTextBox = new TextBox();
stateTextBox.ID = "MyTextBoxID" //This must be the same each postback
//Viewstate will automatically re-populate the textboxes when created like this
MyPlaceHolder.Controls.Add
}
}
If you go that route, you will need to set the AutoPostBack to true on the DDL so it does a server post.
ASKER
Strickdd: If you don't mind, I really need completed working codes. Thanks. About your codes,
it won't work because it is static textbox name. If I have 25 city/states, what the textbox names will be...?
it won't work because it is static textbox name. If I have 25 city/states, what the textbox names will be...?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
A completed and working codes will be really helpful....:-D Thanks.
Given your loosely defined requirements and no knowledge of what your setup is exactly, that is an impossible task. Given the level of knowledge you appear to have, it is well within your ability to take the code provided and make it suit your exact needs.
Experts Exchange is not a place to have people do the work for you, but rather a place to receive assistance on technical problems you are having.
Experts Exchange is not a place to have people do the work for you, but rather a place to receive assistance on technical problems you are having.
function DDLChange()
{
if(document.getElementById
document.getElementById('<
else
document.getElementById('<
}