This documentation is archived and is not being maintained.

DataBind Method (Common)

.NET Framework 1.1

Creates a binding between a server control property and a data source.

public virtual void DataBind()

Inheritance

All controls directly inherit this method from the System.Web.UI.Control class. The following is a list of the classes that inherit the DataBind property from the System.Web.UI.Control class.

Remarks

If a data source has been specified, the control performs the following steps:

  • Erases items currently in the data source
  • Performs data binding

If a control is to be filled by using a data source, the control remains empty until data binding occurs.

For the control to bind the data, you must call the DataBind method. Most ASP.NET mobile controls support data binding, but do not require its use. However, without data binding, the ObjectList control never displays any content. For more information about data binding, see the Data Access and Customization section in the ASP.NET QuickStart documentation.

Example

The following example demonstrates the use of the DataBind method to bind the array to the ObjectList.

Class Task
   Private _TaskName As String
   Private _Editable As String
   Private _Priority As Integer
   
   Public Sub New(TaskName As String, Editable As String, Priority As Integer)
      _TaskName = TaskName
      _Editable = Editable
      _Priority = Priority
   End Sub 'New
   
   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 Priority() As Integer
      Get
         Return _Priority
      End Get
   End Property
End Class 

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

   ArrayList arr = new ArrayList();
   // Start initial creation and filling of array.
   arr.Add (new Task ("Tomorrow's work", "yes", 2));
   arr.Add (new Task ("Today's work", "yes", 1));
   arr.Add (new Task ("Yesterday's work", "No", 3));   
   ObjectList1.DataSource = arr;
   ObjectList1.DataBind();

End Sub

[C#]

class Task
{
   private string _TaskName;
   private string _Editable;
   private int   _Priority;
   public Task(string TaskName, string Editable, int Priority) 
   { 
      _TaskName = TaskName; 
      _Editable = Editable;
      _Priority = Priority;
   }   
   public string TaskName { get { return _TaskName; } }
   public string Editable { get { return _Editable; } }
   public int Priority { get { return _Priority; } }
}
public void Page_Load(Object sender, EventArgs e)
{
   ArrayList arr = new ArrayList();
   // Start initial creation and filling of array.
   arr.Add (new Task ("Tomorrow's work", "yes", 2));
   arr.Add (new Task ("Today's work", "yes", 1));
   arr.Add (new Task ("Yesterday's work", "No", 3));   
   ObjectList1.DataSource = arr;
   ObjectList1.DataBind();
}

See Also

Applies to: System.Web.UI.Control.DataBind Method

Show: