2011-05-30 80 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