0

我是 Asp.net 的新手

我正在创建具有DropDown列表和其他一些控件的网站..

每当我更改下拉选择的索引时,如果它等于其中之一,Item那么我想显示控件,如果不等于,那么我想隐藏这些控件...

在这里,我尝试使用此代码,但没有得到...

  var selectmenu = document.getElementById("<%=ddlCategory.ClientID%>");
    var chosenoption = selectmenu.options[selectmenu.selectedIndex];
     //Controls which are to hidden or visible
    var strCtrlIds =   "lblOrderNumber,txtOrderNumber,btnGetOrderNumber,lblItemNumber,txtItemNumber,lblReason,txtReason,lblMaterial,txtDescription";
     if (chosenoption.value != "Dry End - Single Stack") {
         debugger;
         ToggleGivenControl(strCtrlIds, false);

     }
     else {
         ToggleGivenControl(strCtrlIds, true);
     }
     /**********************************************************
                    Toggle for Display End- Stack Options
     ************************************************************/


     function ToggleGivenControl(strCtrlIds, blnIsVisible) {
         debugger;
         var ctrls = strCtrlIds.toString().split(",");
         var strCtrlId = '';
         for (var intCnt = 0; intCnt < ctrls.length; intCnt++) {
             strCtrlId = ctrls[intCnt];
             var ctrl = document.getElementById(strCtrlId);
             if (ctrl != null) {
                 if (blnIsVisible) {
                     ctrl.style.display = 'block';
                     ctrl.style.visibility = 'visible';
                     ctrl.focus();
                 }
                 else {
                     ctrl.style.display = 'none';
                     ctrl.style.visibility = 'hidden';
                 } //Else End
             } //If End.
         } //For end.
     }

我的 asp.net 代码是

  <asp:DropDown id="ddlCategory" runat="server" />
  <asp:Lable id="lblItem" runat="server" />
  <asp:TextBox id="txtItem" runat="server"/>
 ....

一件事是我使用数据源限制下拉

请问有人能解决我的问题吗?

4

1 回答 1

0

我想像这样。

<asp:DropDown id="ddlCategory" runat="server" onchange="OnDropDownListChange();" />    
function OnDropDownListChange(){
   var selectmenu = document.getElementById("<%=ddlCategory.ClientID%>");
  var chosenoption = selectmenu.options[selectmenu.selectedIndex];
 //Controls which are to hidden or visible
 var strCtrlIds =    "<%=lblOrderNumber.ClientID%>,<%=txtOrderNumber.ClientID%>,<%=btnGetOrderNumber.ClientID%>,<%=txtItemNumber.ClientID%>";
 if (chosenoption.value != "Dry End - Single Stack") {
     debugger;
     ToggleGivenControl(strCtrlIds, false);

 }
 else {
     ToggleGivenControl(strCtrlIds, true);
 }
}
于 2012-12-17T08:04:06.933 回答