2017-05-12 98 views
0

我有选择下拉列表给它一个空的问题,而选择了它后选择下拉列表选项显示隐藏的文本框

下面是代码:

<asp:GridView ID="gridview1" runat="server" AllowPaging="false" Width="99%" > 

    <asp:BoundField DataField="NAME" HeaderText ="Name" HtmlEncode="false"/> 

    <asp:BoundField DataField="ID " HeaderText ="ID " HtmlEncode="false"/> 

     <asp:TemplateField HeaderText ="Location"> 
     <ItemTemplate> 

    <asp:DropDownList ID="ddlfruitAgent" runat="server" onchange="Store_Location_onChange(this)" /> 
    <asp:TextBox ID="StoreLocation" runat="server" TextMode="MultiLine" Rows="2" style="width:97%;display:none" /> 
     </ItemTemplate> 
     </asp:TemplateField> 

的javascript:

function Store_Location_onChange(objThis) { 
    if (objThis.value == "0") { 

     document.getElementById("StoreLocation").style.display = ""; 
    } 
    else { 
     document.getElementById("StoreLocation").value = ""; 
     document.getElementById("StoreLocation").style.display = "none"; 
    } 
} 

回答

1

由于你传递this为对象的参考,你可以这样做

function Store_Location_onChange(objThis) { 
    if (objThis.value == "0") { 
     objThis.nextElementSibling.style.display = ""; 
    } 
    else { 
     objThis.nextElementSibling.value = ""; 
     objThis.nextElementSibling.style.display = "none"; 
    } 
} 

或其他方式周围是

function Store_Location_onChange(objThis) { 
    if (objThis.value == "0") { 
     document.getElementById("<%= StoreLocation.ClientID %>").style.display = ""; 
    } 
    else { 
     documentgetElementById("<%= StoreLocation.ClientID %>").value = ""; 
     document.getElementById("<%= StoreLocation.ClientID %>").style.display = "none"; 
    } 
} 

希望这有助于!

+0

它有一个错误的JavaScript运行时错误:无法设置定义或空引用属性值 而我尝试选择下拉列表 –

+0

控制台这一行' - > objThis.nextElementSibling'并查看返回的是什么! –

+0

下拉列表是后面的代码是一个SQL查询 –

相关问题