Javascript 用ASP:DropDownList中的值填充弹出窗口是很困难的
以下是我当前使用的Javascript,用于选择要在弹出窗口中显示的监视器选定值:Javascript 用ASP:DropDownList中的值填充弹出窗口是很困难的,javascript,asp.net,vb.net,html.dropdownlistfor,Javascript,Asp.net,Vb.net,Html.dropdownlistfor,以下是我当前使用的Javascript,用于选择要在弹出窗口中显示的监视器选定值: var theMonitor = document.getElementById("ctl00_ContentPlaceHolder1_MonitorInductionDDL"); var strUser = theMonitor.options[theMonitor.selectedIndex].text; 这是实际的Dropdownlist代码: <tr>
var theMonitor = document.getElementById("ctl00_ContentPlaceHolder1_MonitorInductionDDL");
var strUser = theMonitor.options[theMonitor.selectedIndex].text;
这是实际的Dropdownlist代码:
<tr>
<td nowrap="nowrap" style="width:132px">
Monitor?</td>
<td nowrap="nowrap" style="width:464px">
<asp:DropDownList ID="MonitorInductionDDL" runat="server" Height="25px"
Width="334px" >
<asp:ListItem Selected="True" Value="0">Yes</asp:ListItem>
<asp:ListItem Value="1">No</asp:ListItem>
</asp:DropDownList>
</td>
</tr>
以下是弹出窗口的图片:
您可能会注意到,我在后台单击了更新按钮,从“辞职”行上的更新按钮触发此弹出窗口,监视器显示为“否”,但显示为“是”
所以我的问题是,我如何才能让弹出窗口监视器中的Dropdownlist成为该列中任何内容的值
老实说,我不知道哪里出了问题,所以快速的帮助和指导会很好,提前谢谢您。我认为错误在第二行,您从ddl的选定文本中获取值。但是您必须为它设置值,如下所示
而不是
var theMonitor = document.getElementById("ctl00_ContentPlaceHolder1_MonitorInductionDDL");
var strUser = theMonitor.options[theMonitor.selectedIndex].text;
输入下面的代码
function showpopup(str1,str2,str3)
{
var theMonitor = document.getElementById("ctl00_ContentPlaceHolder1_MonitorInductionDDL");
theMonitor.options[theMonitor.selectedIndex].text= str3;
}
添加JavaScript调试器断点以检查单击网格后获得的值。如果您得到“否”,但仍然无法将下拉列表的选定文本/值设置为“否”,请确保没有前导/尾随空格
我面临这样的情况
function showpopup(str1,str2,str3)
{
var theMonitor = document.getElementById("ctl00_ContentPlaceHolder1_MonitorInductionDDL");
theMonitor.options[theMonitor.selectedIndex].text= str3;
}