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

Using InPlace and EditForms Modes

This article will show you how you can access the values on insert when you are using the autogenerated edit forms of RadTreeList and you want to do manual inserts. The stress will be on accessing the values, leaving the insert logic to your choice, depending on your own datasource handling. There are generally two options on how to access the inserted values:

  • Using the ExtractValuesFromItem() method

  • Using the column editors of the treelist columns

Accessing the insert 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.

After you get the IDictionary object populated, you can use the provided values to insert a new item into the treelist datasource.

ASPNET
<telerik:RadTreeList RenderMode="Lightweight" ID="RadTreeList1" runat="server" DataKeyNames="EmployeeID" ParentDataKeyNames="ReportsTo"
	AutoGenerateColumns="false" EditMode="EditForms" DataSourceID="SqlDataSource1" OnInsertCommand="RadTreeList1_InsertCommand">
	<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.

ASPNET
<telerik:RadTreeList RenderMode="Lightweight" ID="RadTreeList2" runat="server" DataKeyNames="EmployeeID" ParentDataKeyNames="ReportsTo"
	AutoGenerateColumns="false" EditMode="InPlace" DataSourceID="SqlDataSource1" OnInsertCommand="RadTreeList2_InsertCommand">
	<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>

Note that RadTreeList expects the newly inserted value of the field that is specified as DataKeyNames to be larger than any of the already available values of this field in the datasource.