我是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"/>
....
有一件事是我使用数据源下载了下拉列表
请任何人清楚我的问题吗?
答案 0 :(得分: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);
}
}