Dynamic controls
-
Hi all, I have to make one web page where user can add dropdownlist dynamically. As many time user clicks on one button it add one dropdownlist control to webpage. Is it possible to do this using ASP.NET without java script? Thanks in advance, Priyank
-
Hi all, I have to make one web page where user can add dropdownlist dynamically. As many time user clicks on one button it add one dropdownlist control to webpage. Is it possible to do this using ASP.NET without java script? Thanks in advance, Priyank
You can use a PlaceHolder control. On every click of the button event, create a dropdownlist and add it to the PlaceHolder
protected void btnCreateDropDown_Click(object sender, EventArgs e)
{
PlaceHolder phDropdownlist = new PlaceHolder();
DropDownList dropdown = new DropDownList();
// Use your logic to give the dropdown an ID and a logic to find which data needs
// to bind to each of the dropdowns
dropdown.ID = "SomeName";
dropdown.DataSource = dataset1;
dropdown.DataTextField = "Text";
dropdown.DataValueField = "Value";
dropdown.DataBind();
phDropdownlist.Controls.Add(dropdown);
}