ControlCollection.Remove(Control) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
移除父伺服器控制 ControlCollection 物件中指定的伺服器控制項。
public:
virtual void Remove(System::Web::UI::Control ^ value);
public virtual void Remove(System.Web.UI.Control value);
abstract member Remove : System.Web.UI.Control -> unit
override this.Remove : System.Web.UI.Control -> unit
Public Overridable Sub Remove (value As Control)
參數
- value
- Control
伺服器控制權將被移除。
範例
以下程式碼範例使用 Remove 了從伺服器控制項刪除子控制項的方法 myButton 。 首先,程式碼會使用該 Contains 方法來判斷 是否 myChildControl 包含在 ControlCollection 物件中,若包含,則將其移除。
// Use the Contains method to check whether
// a child control exists, and if it does,
// use the Remove method to delete it.
if (myButton.Controls.Contains(myChildControl))
{
myButton.Controls.Remove(myChildControl);
msgRemove.Text = "You removed myLiteralControl.";
}
else msgRemove.Text="The control to remove does not exist." ;
' Use the Contains method to check whether
' a child control exists, and if it does,
' use the Remove method to delete it.
If myButton.Controls.Contains(myChildControl)
myButton.Controls.Remove(myChildControl)
msgRemove.Text = "You removed myLiteralControl."
Else
msgRemove.Text="The control to remove does not exist."
End If
備註
要從索引位置移除控制項,請使用以下 RemoveAt 方法。