Removing Items from DropDownList
Below is the simple code to remove the items from the dropDownList. In the code below i have created a simple function name clearDropwDownList , the function will take the dropDownList control object as parameter.
At the first line of the function i have declared variable named intTotalItems which will hold the number of items in the dropDownList which is passed to the function. Then i use the for loop to remove the each item in the dropDownList by using the remove(intCounter), statement where intCounter is the current index to be removed.
Add Items from DropDownList
Now how to add new value(s) in the dropDownList, below is the code you can use to add the value to the dropDownList, i have created function for this operation as well, so you need to pass the dropDownList control object , the value field and the text field to be added in the dropDownList as new item.
First i have created the option object to hold the text and the value of the new item and then i assign the values to the text and the value property and at the end added the new option in the dropDownList.
If you have any question regarding this post please ask me
Happy programming :)