Share via


ListDataBindEventArgs Class

Provides parameters for an ItemDataBind event.

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

Example

For each item that is bound to a List control, the OnItemDataBind event calls a user-defined function, SummarizeTask, where one of the arguments it passes is the ListDataBindEventArgs argument. By using the argument's ListItem.Value, this example increments the static variables according to their status and displays the overall status count.

<%@ 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>

Requirements

Namespace: System.Web.UI.MobileControls

Assembly: System.Web.Mobile