Classe ListDataBindEventArgs

Vengono forniti i parametri per un evento ItemDataBind.

public class System.Web.UI.MobileControls.ListDataBindEventArgs : 
   System.EventArgs

Esempio

Per ogni elemento associato a un controllo List, l'evento OnItemDataBind chiama una funzione definita dall'utente, SummarizeTask, in cui uno degli argomenti passati è ListDataBindEventArgs. Utilizzando ListItem.Value dell'argomento, in questo esempio vengono incrementate le variabili statiche in base al relativo stato e viene visualizzato il conteggio dello stato complessivo.

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

<script runat="server">
// Persist across multiple postbacks.
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 array.
      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 SummarizeTask(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;
}

</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="SummarizeTask" 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:Form>

Requisiti

Spazio dei nomi: System.Web.UI.MobileControls

Assembly: System.Web.Mobile