Reputation: 31
Hi How to add items to dynamically created select (html) Control..
thanks
Upvotes: 1
Views: 16430
Reputation: 49245
For adding items on server side, use HtmlSelect.Items property. For example,
var select = control as HtmlSelect; // may not be needed
var items = select.Items;
// Add items to the collection.
items.Add(new ListItem("apples", "1"));
items.Add(new ListItem("bananas", "2"));
items.Add(new ListItem("cherries", "3"));
Upvotes: 8
Reputation: 3631
You can use javascript to do this e.g.
<script type="text/javascript">
function AddItem(Text,Value)
{
// Create an Option object
var opt = document.createElement("option");
// Add an Option object to Drop Down/List Box
document.getElementById("myDropDownList").options.add(opt);
// Assign text and value to Option object
opt.text = Text;
opt.value = Value;
}<script />
Upvotes: 1