2011-05-30 36 views
-1
我有文字

这就好比是“选择”,“未选中”动态设置的ASP的selectedIndex:下拉

动态我想成立“选择”之类

dropdown.selectedIndex = dropdown.Items.FindByText("selected"); 

如何要显示的选择组?请指导

+0

我可以做到这一点的JavaScript? – MayureshP 2011-05-30 11:03:32

回答

2

你几乎没有

dropdown.Items.FindByText("selected").Selected = true; 

编辑

要做到这一点通过JavaScript您将通过下拉的option元素必须循环。像这样的东西

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

我可以在JavaScript中做到吗? – MayureshP 2011-05-30 11:02:23

+0

谢谢@ V4Vendetta – MayureshP 2011-05-30 11:23:20

相关问题