LabelField Property
Sets or returns a value (the name or data field) that identifies the field to use as a label for each item. The default value is empty, which causes the first field in the AllFields collection to be used as a label for each item.
public string LabelField {
get,
set
}
Remarks
This property is ignored if the list view is shown as a table.
Example
The following example demonstrates how to use the LabelField property to specify the contents of the TaskName field as the label in the list view.
Dim arr As New ArrayList()
Class Task
Private _TaskName As String
Private _Editable As String
Public Sub New(TaskName As String, Editable As String)
_TaskName = TaskName
_Editable = Editable
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
End Class 'Task
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Start initial creation and filling of array.
arr.Add(New Task("Tomorrow's work", "yes"))
ObjectList1.DataSource = arr
ObjectList1.LabelField = "TaskName"
ObjectList1.DataBind()
End Sub
[C#]
ArrayList arr = new ArrayList();
class Task
{
private string _TaskName;
private string _Editable;
public Task(string TaskName, string Editable)
{
_TaskName = TaskName;
_Editable = Editable;
}
public string TaskName { get { return _TaskName; } }
public string Editable { get { return _Editable; } }
}
public void Page_Load(Object sender, EventArgs e)
{
// Start initial creation and filling of array.
arr.Add (new Task ("Tomorrow's work", "yes"));
ObjectList1.DataSource = arr;
ObjectList1.LabelField = "TaskName";
ObjectList1.DataBind();
}
See Also
ObjectList Control
Applies to: ObjectList Class