Back to Devexpress

DxTreeList.GetDataItemValue(Object, String) Method

blazor-devexpress-dot-blazor-dot-dxtreelist-dot-getdataitemvalue-x28-system-dot-object-system-dot-string-x29.md

latest3.3 KB
Original Source

DxTreeList.GetDataItemValue(Object, String) Method

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

Namespace : DevExpress.Blazor

Assembly : DevExpress.Blazor.v25.2.dll

NuGet Package : DevExpress.Blazor

Declaration

csharp
public object GetDataItemValue(
    object dataItem,
    string fieldName
)

Parameters

NameTypeDescription
dataItemObject

The data item whose field value should be returned.

| | fieldName | String |

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

|

Returns

TypeDescription
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 :

razor
<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");
    }
}
css
.my-button {
  width: 200px;
}

Implements

GetDataItemValue(Object, String)

GetDataItemValue(Object, String)

See Also

DxTreeList Class

DxTreeList Members

DevExpress.Blazor Namespace