Partager via


ListCommandEventArgs.DefaultCommand Champ

Définition

Définit ou retourne le nom de la commande par défaut. Cette API est obsolète. Pour plus d’informations sur le développement d’applications mobiles ASP.NET, consultez Applications mobiles & Sites avec ASP.NET.

protected: static initonly System::String ^ DefaultCommand;
protected static readonly string DefaultCommand;
 staticval mutable DefaultCommand : string
Protected Shared ReadOnly DefaultCommand As String 

Valeur de champ

Exemples

L’exemple de code suivant montre comment utiliser la DefaultCommand propriété pour spécifier « Check » comme commande par défaut.

Notes

L’exemple de code suivant utilise le modèle de code à fichier unique et peut ne pas fonctionner correctement s’il est copié directement dans un fichier code-behind. Cet exemple de code doit être copié dans un fichier texte vide qui a une extension .aspx. Pour plus d’informations, consultez ASP.NET modèle de code de page Web Forms.

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

<script runat="server">
    private void Page_Load(Object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            // Create array and add the tasks to it.
            ArrayList arr = new ArrayList();
            arr.Add(new Task("Verify transactions", "Done"));
            arr.Add(new Task("Check balance sheet", "Scheduled"));
            arr.Add(new Task("Send report", "Pending"));

            // Bind the List to the ArrayList
            ObjectList1.DataSource = arr;
            ObjectList1.DataBind();
        }
        ObjectList1.DefaultCommand = "Check";
    }

    // Event handler for all ObjectList1 commands
    private void SelectCommand(Object sender, 
        ObjectListCommandEventArgs e)
    {
        if (e.CommandName.ToString() == "Check")
            ActiveForm = Form2;
        else if (e.CommandName.ToString() == "Browse")
            ActiveForm = Form3;
    }

    // Custom class for the ArrayList items
    private class Task
    {
        private String _TaskName, _Status;

        public Task(String TaskName, String Status)
        {
            _TaskName = TaskName;
            _Status = Status;
        }
        public String TaskName
        {
            get { return _TaskName; }
        }
        public String Status
        {
            get { return _Status; }
        }
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<body>
    <mobile:form id="Form1" runat="server">
        <mobile:ObjectList runat="server" id="ObjectList1" 
            OnItemCommand="SelectCommand">
            <Command Name="Check" Text="Check Appointments" />
            <Command Name="Browse" Text="Browse Tasks" />
        </mobile:ObjectList>
    </mobile:form>
    <mobile:Form ID="Form2" Runat="server">
        <mobile:Label ID="Label1" Runat="server">
            Check Appointments</mobile:Label>
        <mobile:Link ID="Link1" Runat="server" 
            NavigateUrl="#Form1">Back</mobile:Link>
    </mobile:Form>
    <mobile:Form ID="Form3" Runat="server">
        <mobile:Label ID="Label2" Runat="server">
            Browse Tasks</mobile:Label>
        <mobile:Link ID="Link2" Runat="server" 
            NavigateUrl="#Form1">Back</mobile:Link>
    </mobile:Form>
</body>
</html>

Remarques

Lorsqu’il est défini, tente ObjectList d’afficher un raccourci pour appeler la commande par défaut. En HTML, le rendu par défaut dans ListView affiche le premier champ sous la forme d’un lien vers le DetailsViewObjectListdu . En définissant la DefaultCommand propriété, le fait de cliquer sur le lien appelle la commande par défaut. L’appel de la commande par défaut déclenche l’événement ItemCommand . Le CommandName de l’objet ObjectListCommandEventArgs est défini sur la valeur de la DefaultCommand propriété .

Même si une commande par défaut est définie, vous devez inclure une commande portant le même nom dans la collection de commandes. Si le contrôle ne peut pas afficher un élément graphique qui inclut un raccourci pour la commande par défaut, la commande par défaut est toujours disponible en rendant la ObjectList.Commands collection.

S’applique à

Voir aussi