开发者

dynamically set selectedIndex of asp:dropdown

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;
       }
   }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜