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 |
---|---|---|
data |
Object | The data item whose field value should be returned. |
field |
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");
}
}