Classe ListCommandEventArgs

Vengono forniti i dati relativi all'evento ItemCommand di un controllo List.

public class System.Web.UI.MobileControls.ListCommandEventArgs : 
   System.Web.UI.WebControls.CommandEventArgs

Esempio

In questo esempio viene illustrata la modalità d'uso dell'oggetto ListCommandEventArgs e delle proprietà ListItem per visualizzare il relativo contenuto mediante l'assegnazione alla proprietà di testo di un'etichetta.

<%@ Page Inherits="System.Web.UI.MobileControls.MobilePage" 
   Language="c#" Debug="true" %>

<script runat="server">
// Persist across multiple postbacks.
static int i,j,k;

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; } }
}

public void Page_Load(Object sender, EventArgs e)
{
   if (!IsPostBack)
   {
      // Initialize static variables to zero.
      i = j = k = 0;

      // Set initial settings for tasks.
      List1.DataValueField="Status";
      List1.DataTextField="TaskName";

      // 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"));

      // Associate and bind the List to the ArrayList
      List1.DataSource = arr;
      List1.DataBind ();

      if (List1.HasItemCommandHandler == true)
      {
         Label1.Text = "List has ItemCommand event handler";
      }
      else
      {
         Label1.Text = "List has no ItemCommand event handler";
      }
   }
}

void TaskSummary(Object sender, ListDataBindEventArgs e)
{ 
   switch (e.ListItem.Value)
   {
      case "Done":
         i++;
         break;
      case "Scheduled":
         j++;
         break;
      case "Pending":
         k++;
         break;
      Default:
         break;
   }

   Label2.Text = "You have " + i.ToString() + " tasks done, " +
      j.ToString() + " tasks scheduled, and " + k.ToString() + 
      " tasks Pending.";
}

void TaskStatus(Object sender, ListCommandEventArgs e)
{
   Label3.Text = e.ListItem.Text +" is " + e.ListItem.Value;
}

void ChangeDataSource(Object sender, EventArgs e)
{
   // Reset static variables to zero.
   i = j = k = 0;
   ArrayList _arr = new ArrayList();
   _arr.Add (new Task ("Verify bank transactions", "Done"));
   _arr.Add (new Task ("Check company balance sheet", "Done"));
   _arr.Add (new Task ("Audit report", "Scheduled"));
   List1.DataSource = _arr;
   List1.DataBind ();   
}

</script>

<mobile:Form runat="server" id="Form1" >
   <mobile:Label runat="server" id="Label1" ForeColor=green 
      Font-Italic=true />
   <mobile:List runat="server" id="List1" 
      OnItemDataBind="TaskSummary" OnItemCommand = "TaskStatus"/>
   <mobile:Label runat="server" id="Label2" Font-Italic=true 
      ForeColor=Red />
   <mobile:Label runat="server" id="Label3" Font-Italic=true 
      ForeColor=Red />
   <mobile:Command runat="server" id="Command1" 
      Text="See 2nd Tasklist" OnClick="ChangeDataSource" />
</mobile:Form>

Requisiti

Spazio dei nomi: System.Web.UI.MobileControls

Assembly: System.Web.Mobile

Vedere anche

ItemCommand | Classe List | Classe MobileListItem | Controllo List