Add Method (ObjectListFieldCollection)
Adds a field to the end of the collection.
public void Add(
System.Web.UI.MobileControls.ObjectListField field
)
Parameters
- field
The ObjectListField to add to the end of the collection.
Remarks
This method is not available in the read-only IObjectListFieldCollection interface.
Adding a field to the field collection of an object list changes the data-binding behavior of the control and requires you to bind data to the control again.
Example
The following example demonstrates how to use the Add method to add a field (ListField1
) to the end of the ObjectListFieldCollection.
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
Dim arr As ArrayList = 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.
ObjectList1.DataSource = arr
ObjectList1.DataBind()
ObjectList1.AutoGenerateFields = False
Dim ListField1 As New ObjectListField()
ListField1.DataField = "TaskName"
ListField1.Title = "Task Name"
ObjectList1.Fields.Add(ListField1)
ObjectList1.DataBind()
End If
[C#]
public void Page_Load(Object sender, EventArgs e)
{
public void Page_Load(Object sender, EventArgs e)
{
If (!IsPostBack)
{
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.
ObjectList1.DataSource = arr;
ObjectList1.DataBind();
ObjectList1.AutoGenerateFields=false ;
ObjectListField ListField1 = new ObjectListField();
ListField1.DataField = "BookName";
ListField1.Title = "BookName";
ObjectList1.Fields.Add(ListField1);
ObjectList1.DataBind();
}
}
See Also
AddAt Method | Clear Method (Common) | Remove Method (ObjectListFieldCollection) | RemoveAt Method (Common)
Applies to: ObjectListFieldCollection Class