AddAt Method (ObjectListFieldCollection)
Adds a field at the location in the collection specified by the index parameter.
public void AddAt(
int index,
System.Web.UI.MobileControls.ObjectListField field
)
Parameters
- index
The location in the collection at which to add the field. - field
The field to add at the specified location in the collection.
Remarks
A –1 value for the index parameter specifies that the field is added to the end of the collection.
Adding a field to the fields 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 AddAt method to add a field 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.AddAt(0, 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.AddAt(0,ListField1);
ObjectList1.DataBind();
}
}
See Also
Add Method (ObjectListFieldCollection) | Clear Method (Common) | Remove Method (ObjectListFieldCollection) | RemoveAt Method (Common)
Applies to: ObjectListFieldCollection Class