ObjectListCommand Klasa

Definicja

Ostrzeżenie

Ten interfejs API jest teraz przestarzały.

Reprezentuje polecenie w kontrolce ObjectList ASP.NET Mobile.Represents a command in an ObjectList ASP.NET mobile control. Informacje o sposobach tworzenia aplikacji mobilnych ASP.NET można znaleźć w temacie Mobile Apps & witryny z ASP.NET.For information about how to develop ASP.NET mobile applications, see Mobile Apps & Sites with ASP.NET.

public ref class ObjectListCommand
[System.Web.UI.MobileControls.PersistName("Command")]
[System.Obsolete("The System.Web.Mobile.dll assembly has been deprecated and should no longer be used. For information about how to develop ASP.NET mobile applications, see http://go.microsoft.com/fwlink/?LinkId=157231.")]
public class ObjectListCommand
type ObjectListCommand = class
Public Class ObjectListCommand
Dziedziczenie
ObjectListCommand
Atrybuty

Przykłady

Poniższy przykład pokazuje, jak utworzyć obiekt ObjectListCommand.The following example shows how to create an ObjectListCommand object. Ten przykład jest częścią większego, bardziej kompletnego przykładu dla ObjectList przegląd.This example is part of a larger, more complete example for the ObjectList overview.

<%@ Page Language="C#" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>

<script runat="server">
    //System.Web.UI.MobileControls.ObjectListItem item;
    //System.Web.UI.MobileControls.ObjectListItemCollection itemColl;
    // Get the persisted array through postbacks.
    ArrayList arr = new ArrayList();
    public void Page_Load(Object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // Create and fill the array
            arr.Add(new Task("Tomorrow's work", "Yes", 1));
            arr.Add(new Task("Today's work", "Yes", 1));
            arr.Add(new Task("Yesterday's work", "No", 1));
            
            // Persist the array in the Session object
            Session["MyArrayList"] = arr;

            // Associate and bind array to the 
            // ObjectList for each postback.
            ObjectList1.DataSource = arr;
            ObjectList1.LabelField = "TaskName";
            ObjectList1.DataBind();
        }
    }

    private void ItemCommand_Click(Object sender, 
        ObjectListCommandEventArgs e)
    {
        // Get the array from the Session object
        arr = (ArrayList)Session["MyArrayList"];

        // Remove selected item from the ObjectLis
        int i = ObjectList1.SelectedIndex;
        arr.RemoveAt(i);
        Session["MyArrayList"] = arr;

        // Re-Bind ObjectList to altered ArrayList.
        ObjectList1.DataSource = arr;
        ObjectList1.LabelField = "TaskName";
        ObjectList1.DataBind();
        ObjectList1.ViewMode = ObjectListViewMode.List;
    }

    void ItemCommands_Show(Object sender, 
        ObjectListShowCommandsEventArgs e) 
    {
        // Check conditions, and add or remove 
        // commands in the detail view.
        if (e.ListItem["Editable"].Equals("No"))
            ObjectList1.Commands.RemoveAt(0);
        else if (ObjectList1.Commands.Count < 1)
            ObjectList1.Commands.Add(new 
                ObjectListCommand("Delete", "Delete"));
    }

    private class Task
    {
        private string _TaskName;
        private string _Editable;
        private int _Days;
        public Task(string TaskName, string Editable, int Days)
        {
            _TaskName = TaskName;
            _Editable = Editable;
            _Days = Days;
        }
        public string TaskName
        { get { return _TaskName; } }
        public string Editable
        { get { return _Editable; } }
        public int Days
        { get { return _Days; } }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:Form runat="server" id="Form1" >
        <mobile:ObjectList runat="server" id="ObjectList1" 
            OnItemCommand="ItemCommand_Click" 
            OnShowItemCommands="ItemCommands_Show" >
            <Command Name="Delete" Text="Delete" />
        </mobile:ObjectList>
        <mobile:Label runat="server" id="Label1" />
        <mobile:Label runat="server" id="Label2" />
    </mobile:Form>
</body>
</html>
<%@ Page Language="VB" 
    Inherits="System.Web.UI.MobileControls.MobilePage" %>
<%@ Register TagPrefix="mobile" 
    Namespace="System.Web.UI.MobileControls" 
    Assembly="System.Web.Mobile" %>

<script runat="server">
    ' System.Web.UI.MobileControls.ObjectListItem item
    ' System.Web.UI.MobileControls.ObjectListItemCollection itemColl
    ' Get the persisted array through postbacks.
    Private arr As New ArrayList()
    Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        If Not IsPostBack Then
            ' Create and fill the array
            arr.Add(new Task("Tomorrow's work", "Yes", 1))
            arr.Add(new Task("Today's work", "Yes", 1))
            arr.Add(new Task("Yesterday's work", "No", 1))
            
            ' Persist the array in the Session object
            Session("MyArrayList") = arr

            ' Associate and bind array to the 
            ' ObjectList for each postback.
            ObjectList1.DataSource = arr
            ObjectList1.LabelField = "TaskName"
            ObjectList1.DataBind()
            
        End If
    End Sub

    Private Sub SelectCommand(ByVal sender As Object, _
         ByVal e As ObjectListCommandEventArgs)
        ' Get the array from the Session object
        arr = CType(Session("MyArrayList"), ArrayList)

        ' Remove selected item from the ObjectLis
        Dim i As Integer = ObjectList1.SelectedIndex
        arr.RemoveAt(i)
        Session("MyArrayList") = arr

        ' Re-Bind ObjectList to altered ArrayList.
        ObjectList1.DataSource = arr
        ObjectList1.LabelField = "TaskName"
        ObjectList1.DataBind()
        ObjectList1.ViewMode = ObjectListViewMode.List
    End Sub

    Public Sub ShowTaskDetail(ByVal sender As Object, _
        ByVal e As ObjectListShowCommandsEventArgs)

        ' Check conditions, and add or remove 
        ' commands in the detail view.
        If e.ListItem("Editable").Equals("No") Then
            ObjectList1.Commands.RemoveAt(0)
        ElseIf ObjectList1.Commands.Count < 1 Then
            ObjectList1.Commands.Add(New ObjectListCommand("Delete", "Delete"))
        End If
    End Sub

    Private Class Task
        Private _TaskName As String
        Private _Editable As String
        Private _Days As Integer
        Public Sub New(ByVal TaskName As String, _
            ByVal Editable As String, ByVal Days As Integer)

            _TaskName = TaskName
            _Editable = Editable
            _Days = Days
        End Sub
        Public ReadOnly Property TaskName() As String
            Get
                Return _TaskName
            End Get
        End Property
        Public ReadOnly Property Editable() As String
            Get
                Return _Editable
            End Get
        End Property
        Public ReadOnly Property Days() As Integer
            Get
                Return _Days
            End Get
        End Property
    End Class
</script>

<html xmlns="http:'www.w3.org/1999/xhtml" >
<body>
    <mobile:Form runat="server" id="Form1" >
        <mobile:ObjectList runat="server" id="ObjectList1" 
            OnItemCommand="SelectCommand" OnShowItemCommands="ShowTaskDetail" >
            <Command Name="Delete" Text="Delete" />
        </mobile:ObjectList>
        <mobile:Label runat="server" id="Label1" />
        <mobile:Label runat="server" id="Label2" />
    </mobile:Form>
</body>
</html>

Uwagi

Obiekt ObjectListCommand może być zadeklarowany jako element <command> w deklaracji ObjectList.An ObjectListCommand object can be declared as a <command> element within the declaration of an ObjectList.

Obiekt ObjectListCommand może być również skonstruowany i dodany programowo do ObjectList, przez dodanie go do kolekcji elementów członkowskich Commands formantu.An ObjectListCommand object can be also constructed, and added programmatically to an ObjectList, by adding it to the control's Commands member collection.

Konstruktory

ObjectListCommand()

Inicjuje nowe wystąpienie klasy ObjectListCommand klasy.Initializes a new instance of the ObjectListCommand class. {1&gt;Ten interfejs API jest nieaktualny.&lt;1}This API is obsolete. Informacje o sposobach tworzenia aplikacji mobilnych ASP.NET można znaleźć w temacie Mobile Apps & witryny z ASP.NET.For information about how to develop ASP.NET mobile applications, see Mobile Apps & Sites with ASP.NET.

ObjectListCommand(String, String)

Inicjuje nowe wystąpienie klasy ObjectListCommand klasy.Initializes a new instance of the ObjectListCommand class. {1&gt;Ten interfejs API jest nieaktualny.&lt;1}This API is obsolete. Informacje o sposobach tworzenia aplikacji mobilnych ASP.NET można znaleźć w temacie Mobile Apps & witryny z ASP.NET.For information about how to develop ASP.NET mobile applications, see Mobile Apps & Sites with ASP.NET.

Właściwości

Name

Pobiera nazwę polecenia.Gets the name of the command. {1&gt;Ten interfejs API jest nieaktualny.&lt;1}This API is obsolete. Informacje o sposobach tworzenia aplikacji mobilnych ASP.NET można znaleźć w temacie Mobile Apps & witryny z ASP.NET.For information about how to develop ASP.NET mobile applications, see Mobile Apps & Sites with ASP.NET.

Text

Pobiera lub ustawia tekst, który ma być wyświetlany w poleceniu.Gets or sets the text that is to appear in the command. Wartość domyślna to pusty ciąg.The default is an empty string. {1&gt;Ten interfejs API jest nieaktualny.&lt;1}This API is obsolete. Informacje o sposobach tworzenia aplikacji mobilnych ASP.NET można znaleźć w temacie Mobile Apps & witryny z ASP.NET.For information about how to develop ASP.NET mobile applications, see Mobile Apps & Sites with ASP.NET.

Metody

Equals(Object)

Określa, czy określony obiekt jest równy bieżącemu obiektowi.Determines whether the specified object is equal to the current object.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.Serves as the default hash function.

(Odziedziczone po Object)
GetType()

Pobiera Type bieżącego wystąpienia.Gets the Type of the current instance.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy skróconą kopię bieżącego Object.Creates a shallow copy of the current Object.

(Odziedziczone po Object)
ToString()

Zwraca ciąg, który reprezentuje bieżący obiekt.Returns a string that represents the current object.

(Odziedziczone po Object)

Zabezpieczenia

AspNetHostingPermission
dla działania w środowisku hostowanym.for operating in a hosted environment. Wartość żądania: InheritanceDemand; Wartość uprawnienia: Minimal.Demand value: InheritanceDemand; Permission value: Minimal.

Dotyczy

Zobacz też