共用方式為


Remove 方法 (ObjectListCommandCollection)

傳回具特定名稱的命令。

public void Remove(
   string s
)

參數

  • s
    要移除的命令名稱。此方法移除集合中符合此值的第一個命令。

範例

下列範例示範如何使用 Remove 方法從 ObjectListCommandCollection 移除項目。布林 (Boolean) flag 是在應用程中的其他地方設定的全域變數。

  Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
 
     Command1 = New ObjectListCommand("Command1Text", "Command1Value")
     Command1.Name = "cmd1"
     Command2 = New ObjectListCommand("Command2Text", "Command2Value")
     Command2.Name = "cmd2"
     ObjectList1.Commands.Add(Command1)
     ObjectList1.Commands.Add(Command2)
   
End Sub

Sub SelectCommand(sender As Object, e As ObjectListShowCommandsEventArgs)
   If flag Then
      ObjectList1.Commands.Remove("cmd2")
   Else
      ObjectList1.Commands.Remove("cmd1")
   End If
End Sub 'SelectCommand

[C#]

public void Page_Load(Object sender, EventArgs e)
{
   Command1 = new ObjectListCommand("Command1Text", "Command1Value");
   Command1.Name = "cmd1";
   Command2 = new ObjectListCommand("Command2Text", "Command2Value");
   Command2.Name = "cmd2";
   ObjectList1.Commands.Add(Command1);
   ObjectList1.Commands.Add(Command2);
}
void SelectCommand(Object sender, ObjectListShowCommandsEventArgs e)
{
   if (flag)
   {
      ObjectList1.Commands.Remove("cmd2");
   }
   else
   {
      ObjectList1.Commands.Remove("cmd1");
   }  
}   

請參閱

Remove 方法 (DeviceSpecificChoiceCollection) | Remove 方法 (MobileListItemCollection) | Remove 方法 (ObjectListFieldCollection) | Remove 方法 (StyleSheet)

套用至:ObjectListCommandCollection 類別