/* ------------------------------------------------------
* Description: Common Operations of select element Javascript
* 1. determine whether an item with the specified value exists
* 2. Add an item
* 3. Delete all items whose values are Value
* 4. Option for deleting an index
* 5. Update the value and text of the index.
* 6. Set the first item of the specified text in the SELECT statement to be selected.
* 7. Set the first item of the specified value in the SELECT statement to be selected.
* 8. Obtain the value of the selected item.
* 9. Obtain the index of the selected item.
* 10. Get the text of the selected item.
* 11. Clear all options
------------------------------------------------------- */
// 1. determine whether an item with the specified value exists
Function Existvalue (OBJ, value ){
For ( VaR I = 0 ; I < OBJ. Options. length; I ++ ){
If (Obj. Options [I]. Value = Value ){
Return True ;
}
}
Return False ;
}
// 2. Add an item
Function Additem (OBJ, text, value ){
VaR Varitem = New Option (text, value );
OBJ. Options. Add (varitem );
}
// 3. Delete all items with a value
Function Removeitems (OBJ, value ){
For ( VaR I = 0 ; I < OBJ. Options. length; I ++ ){
If (Obj. Options [I]. Value = Value ){
OBJ. Remove (I );
}
}
}
// 4. Option for deleting an index
Function Removeitem (OBJ, index ){
OBJ. Remove (INDEX );
}
// 5. Update the value and text of the index.
Function Updateitem (OBJ, index, value, text ){
OBJ. Options [Index]. Value = Value;
OBJ. Options [Index]. Text = Text;
}
// 6. Set the first item of the specified text in the SELECT statement to be selected.
Function Selectitembytext (OBJ, text ){
VaR Isexit = False ;
For ( VaR I = 0 ; I < OBJ. Options. length; I ++ ){
If (Obj. Options [I]. Text = Text ){
OBJ. Options [I]. Selected = True ;
Return True ;
}
}
Return False ;
}
// 7. Set the first item of the specified value in the SELECT statement to be selected.
Function Selectitembyvalue (OBJ, value ){
VaR Isexit = False ;
For ( VaR I = 0 ; I < OBJ. Options. length; I ++ ){
If (Obj. Options [I]. Value = Value ){
OBJ. Options [I]. Selected = True ;
Return True ;
}
}
Return False ;
}
// 8. Obtain the value, index, and text of the selected item.
Function Getvalue (OBJ ){
Return OBJ. value;
}
// 9. Obtain the index of the selected item.
Function Getindex (OBJ ){
Return OBJ. selectedindex;
}
// 10. Get the text of the selected item.
Function Gettext (OBJ ){
Return OBJ. Options [obj. selectedindex]. text;
}
// 11. Clear all options
Function Clear (OBJ ){
OBJ. Options. Length = 0 ;
}
. Net assigns Default ValueCode
Dropdownlist1.selectedvalue = String;
// String is the value selected by dropdownlist when you first enter the page.
// The following can be set based on text and value.
Dropdownlist1.items. findbytext (string). Selected = True ;
Dropdownlist1.items. findbyvalue (string). Selected = True ;