编辑时我想在使用 javascript 检查 MYCheckBox 时隐藏 MyTextBox。我可以使用在 ParentFormView 中找到控制
var MyTextboxINParentFV= document.getElementById('<%=ParentFormView.FindControl("MyTextboxINParentFV").ClientID %>');
但是现在我无法在ChildFormView中获取控件,有人可以帮我吗?
<asp:formview ID="ParentFormview" runat="server">
<ItemTemplate>
<asp:TextBox ID="MyTextBoxInParentFV" runat="server"></asp:TextBox>
<asp:CheckBox ID="MYCheckBoxInParentFV" runat="server"></asp:CheckBox>
<asp:FormView ID ="ChildFormView1" runat="server">
<ItemTemplate>
<asp:TextBox ID="MyTextBoxInChildFV" runat="server"></asp:TextBox>
<asp:CheckBox ID="MYCheckBoxInChildFV" runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:FormView>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="MyTextBoxInParentFv" runat="server"></asp:TextBox>
<asp:CheckBox ID="MYCheckBoxInParentFV" runat="server"></asp:CheckBox>
<asp:FormView ID="ChildFormView2" runat="server">
<EditItemTemplate>
<asp:TextBox ID="MyTextBoxInChildFV" runat="server"></asp:TextBox>
<asp:CheckBox ID="MYCheckBoxInChildFV" runat="server"></asp:CheckBox>
</EditItemTemplate>
</asp:FormView>
</EditItemTemplate>
</asp:formview>
最佳答案
您可以为内部 FormView 的控件设置类名:
<asp:FormView ID ="ChildFormView1" runat="server">
<ItemTemplate>
<asp:TextBox ID="MyTextBoxInChildFV" runat="server" CssClass="childTextBox"></asp:TextBox>
<asp:CheckBox ID="MYCheckBoxInChildFV" runat="server" CssClass="childCheckBox"></asp:CheckBox>
</ItemTemplate>
</asp:FormView>
并使用该类名检索它们:
var childFV = document.getElementById('<%=ParentFormView.FindControl("ChildFormView1").ClientID %>');
var childTextBoxes = childFV.getElementsByClassName('childTextBox');
var childCheckBoxes = childFV.getElementsByClassName('childCheckBox');
关于javascript - 使用 Javascript 在嵌套 FormView 中隐藏/显示控件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35958941/