I am having text which is to be shown selected like "selected", "unselected"
dynamically I wanted to开发者_开发技巧 set "selected" like
dropdown.selectedIndex = dropdown.Items.FindByText("selected");
how to set? please guide
You are almost there
dropdown.Items.FindByText("selected").Selected = true;
EDIT
To achieve this via javascript you will have to loop through the option
elements of the dropdown. something like this
function setIndexByText()
{
drp = document.myform.selectcontrol; //this would be your dropdown
str = "selected";
for (indx=0; indx < drp.options.length; indx++)
{
if (drp.options[indx].text == str)
{
drp.selectedIndex = indx;
}
}
}
精彩评论