【问题标题】:how to enable a control like dropdownlist which is inside a panel that is disabled如何启用禁用的面板内的下拉列表等控件
【发布时间】:2015-02-02 20:20:13
【问题描述】:

我有一个禁用的面板。因此面板内的所有控件都被禁用。在回发时,我只需要启用一个禁用面板内的控件。请让我知道我们如何实现这一目标。下面是代码

 <asp:Panel ID="testPanel" runat="server">
 <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:DropDownList ID="dropdownlist" runat="server"></asp:DropDownList>
</asp:Panel>

代码隐藏 aspx.cs

testpanel.Enabled = false;
dropdownlist.Enavbled=true;

此处的下拉列表未启用。 请让我知道启用它的方法。遍历面板是一种性能,因为它里面有很多控件。所以我需要一种更好的方法来启用 D​​isabled Panel 中的 DropDownList。

【问题讨论】:

  • 除非显示父元素,否则无法显示子元素。

标签: c# asp.net code-behind


【解决方案1】:

由于that property 是继承的(与Visible 相同的方式),因此您不能在已禁用的容器控件中启用单个控件。所以唯一的办法是启用Panel和这个控件,但禁用面板中的所有其他控件。

dropdownlist.Enabled = true;
testpanel.Enabled = dropdownlist.Enabled;
// disable all other controls in the panel
TextBox1.Enabled = false;

MSDN:

此属性沿控件层次结构向下传播。如果您禁用一个 容器控件,该容器内的子控件也是 禁用。有关详细信息,请参阅 IsEnabled 属性。

【讨论】:

  • 谢谢。会改变你建议的方式
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-10-12
  • 1970-01-01
  • 2013-09-17
  • 1970-01-01
  • 1970-01-01
  • 2015-06-18
相关资源
最近更新 更多