New to Telerik UI for ASP.NET AJAXStart a free 30-day trial

Using Inplace and EditForms Modes

When you want to do manual updates of the treelist data source, in order to do so, you need to get hold of the edited values in the edit form before performing your custom updating logic. This article will elaborate on the two ways to access these values.

Accessing the edited values using ExtractValuesFromItem() method

The ExtractValuesFromItem(dictionaryObject, editableItem, includePrimaryKey) method of RadTreeList takes the following arguments:

  • IDictionary dictionaryObject - the collection which will hold the values, using the column UniqueName of each edit field as a key.

  • TreeListEditableItem - the current editable item from which the values will be extracted.

  • bool includePrimaryKey - indicates whether the primary key value for the current item should be extracted along with the other values.

It would be easy to recognize the currently updated item by its DataKeyValue if the includePrimaryKey is true, thus including this value in the dictionary object.

ASPNET
<telerik:RadTreeList RenderMode="Lightweight" ID="RadTreeList1" runat="server" DataKeyNames="EmployeeID" ParentDataKeyNames="ReportsTo"
	AutoGenerateColumns="false" DataSourceID="SqlDataSource1"
	OnUpdateCommand="RadTreeList1_UpdateCommand">
	<Columns>
		<telerik:TreeListBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" UniqueName="EmployeeID"
			ReadOnly="true" />
		<telerik:TreeListBoundColumn DataField="LastName" HeaderText="LastName" UniqueName="LastName" />
		<telerik:TreeListBoundColumn DataField="FirstName" HeaderText="FirstName" UniqueName="FirstName" />
		<telerik:TreeListBoundColumn DataField="Title" HeaderText="Title" UniqueName="Title" />
		<telerik:TreeListDateTimeColumn DataField="HireDate" HeaderText="HireDate" UniqueName="HireDate" />
		<telerik:TreeListBoundColumn DataField="ReportsTo" HeaderText="ReportsTo" UniqueName="ReportsTo"
			ReadOnly="true" />
		<telerik:TreeListEditCommandColumn UniqueName="EditColumn" />
	</Columns>
</telerik:RadTreeList>

Accessing the insert values using column editors

This can be achieved by getting hold of the current editable item and then accessing each column editor by column UniqueName. Then you just get the value from the control that the editor holds by using the control's own API.

If you need to access the DataKeyValue of the currently edited item, you should keep in mind that the TreeListEditableItem should be cast to TreeListDataItem if you are using InPlace edit mode, and to TreeListEditFormItem if you are using EditForms . Then you can use the GetDataKeyValue("DataKeyNames") method.

ASPNET
<telerik:RadTreeList RenderMode="Lightweight" ID="RadTreeList2" runat="server" DataKeyNames="EmployeeID" ParentDataKeyNames="ReportsTo"
	AutoGenerateColumns="false" DataSourceID="SqlDataSource1"
	OnUpdateCommand="RadTreeList2_UpdateCommand">
	<Columns>
		<telerik:TreeListBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" UniqueName="EmployeeID"
			ReadOnly="true" />
		<telerik:TreeListBoundColumn DataField="LastName" HeaderText="LastName" UniqueName="LastName" />
		<telerik:TreeListBoundColumn DataField="FirstName" HeaderText="FirstName" UniqueName="FirstName" />
		<telerik:TreeListBoundColumn DataField="Title" HeaderText="Title" UniqueName="Title" />
		<telerik:TreeListDateTimeColumn DataField="HireDate" HeaderText="HireDate" UniqueName="HireDate" />
		<telerik:TreeListBoundColumn DataField="ReportsTo" HeaderText="ReportsTo" UniqueName="ReportsTo"
			ReadOnly="true" />
		<telerik:TreeListEditCommandColumn UniqueName="EditColumn" />
	</Columns>
</telerik:RadTreeList>