Skip to main content
All docs
V24.2

DxTreeList.GetDataItemValue(Object, String) Method

Returns the value of the specified field for the specified data item.

Namespace: DevExpress.Blazor

Assembly: DevExpress.Blazor.v24.2.dll

NuGet Package: DevExpress.Blazor

Declaration

public object GetDataItemValue(
    object dataItem,
    string fieldName
)

Parameters

Name Type Description
dataItem Object

The data item whose field value should be returned.

fieldName String

The name of the data field whose value should be returned.

Returns

Type Description
Object

The field value.

Remarks

Call the GetDataItemValue method when the TreeList is bound to a collection of anonymous objects. In other cases, you can cast a data item to a required type and use the {DataItem.FieldName} notation instead. You can also call the GetRowValue(Int32, String) method to get a field value for a data row with the specified visible index.

The following example calls the GetDataItemValue method to get the selected data item’s Name:

<style>
    .my-button {
        width: 200px;
    }
</style>

<DxTreeList @ref="MyTreeList"
            Data="TreeListData"
            KeyFieldName="Id"
            ParentKeyFieldName="ParentId"
            SelectionMode="TreeListSelectionMode.Single"
            @bind-SelectedDataItem="@SelectedDataItem">
    <Columns>
        <DxTreeListSelectionColumn />
        <DxTreeListDataColumn FieldName="Name" Caption="Task" />
        <DxTreeListDataColumn FieldName="EmployeeName" />
        <DxTreeListDataColumn FieldName="StartDate" />
        <DxTreeListDataColumn FieldName="DueDate" />
    </Columns>
</DxTreeList>
<p />
<DxButton Click="OnGetSelectedTask" CssClass="my-button" Text="Get Selected Task" />
<p />
Selected Task: @SelectedTaskInfo

@code {
    ITreeList MyTreeList { get; set; }
    object TreeListData { get; set; }
    object SelectedDataItem { get; set; }
    string SelectedTaskInfo { get; set; }

    void OnGetSelectedTask() {
        SelectedTaskInfo = (string)MyTreeList.GetDataItemValue(SelectedDataItem, "Name");
    }
    protected override void OnInitialized() {
        TreeListData = new[] {
            new { Id = 1, ParentId = 0, Name = "Simplify & Clarify Product Messaging", EmployeeName = "John Heart", StartDate = new DateTime(2018, 4, 3), DueDate = new DateTime(2018, 4, 14)},
            new { Id = 2, ParentId = 1, Name = "Prepare Financial Reports", EmployeeName = "Samantha Bright", StartDate = new DateTime(2018, 4, 3), DueDate = new DateTime(2018, 4, 7)},
            new { Id = 3, ParentId = 1, Name = "Prepare Marketing Plan", EmployeeName = "Arthur Miller", StartDate = new DateTime(2018, 4, 7), DueDate = new DateTime(2018, 4, 14)},
            new { Id = 4, ParentId = 0, Name = "Create Action Plan To Improve Customer Engagement", EmployeeName = "Robert Reagan", StartDate = new DateTime(2017, 8, 8), DueDate = new DateTime(2018, 4, 8)},
            new { Id = 5, ParentId = 4, Name = "Update Personnel Files", EmployeeName = "Greta Sims", StartDate = new DateTime(2017, 8, 8), DueDate = new DateTime(2017, 10, 18)},
            new { Id = 6, ParentId = 4, Name = "Review Health Insurance Options", EmployeeName = "Brett Wade", StartDate = new DateTime(2017, 9, 27), DueDate = new DateTime(2017, 11, 10)},
            new { Id = 7, ParentId = 4, Name = "Choose Between PPO And HMO Health Plan", EmployeeName = "Sandra Johnson", StartDate = new DateTime(2017, 12, 13), DueDate = new DateTime(2018, 3, 23)},
            new { Id = 8, ParentId = 4, Name = "Update Google Adwords Strategy", EmployeeName = "Ed Holmes", StartDate = new DateTime(2017, 8, 23), DueDate = new DateTime(2017, 12, 23)},
            new { Id = 9, ParentId = 4, Name = "Create New Brochure Design", EmployeeName = "Barb Banks", StartDate = new DateTime(2018, 1, 3), DueDate = new DateTime(2018, 3, 14)},
            new { Id = 10, ParentId = 0, Name = "Increase Average Subscription Price", EmployeeName = "Wally Hobbs", StartDate = new DateTime(2017, 8, 9), DueDate = new DateTime(2017, 9, 13) }
        };
    }
}

Blazor TreeList Get Data Item Value

See Also