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.
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.
protectedvoidRadTreeList1_UpdateCommand(object sender,TreeListCommandEventArgs e){//Canceling out the automatic data source operation (needed if you use a data source control)
e.Canceled =true;//Using the ExtractValuesFromItem() method to get hold of the edited valuesSystem.Collections.Specialized.OrderedDictionary newValues =newSystem.Collections.Specialized.OrderedDictionary();TreeListEditableItem editedItem = e.Item asTreeListEditableItem;
e.Item.OwnerTreeList.ExtractValuesFromItem(newValues, editedItem,true);//Updating logic follows, this part depends on your own custom way of performing CRUD operations
SqlDataSource1.UpdateParameters["EmployeeID"].DefaultValue = newValues["EmployeeID"].ToString();
SqlDataSource1.UpdateParameters["LastName"].DefaultValue = newValues["LastName"].ToString();
SqlDataSource1.UpdateParameters["FirstName"].DefaultValue = newValues["FirstName"].ToString();
SqlDataSource1.UpdateParameters["Title"].DefaultValue = newValues["Title"].ToString();
SqlDataSource1.UpdateParameters["HireDate"].DefaultValue = newValues["HireDate"].ToString();
SqlDataSource1.Update();//Closing the edit form and rebinding the treelist control
RadTreeList1.EditIndexes.Clear();
RadTreeList1.Rebind();}
VB.NET
ProtectedSub RadTreeList1_UpdateCommand(ByVal sender AsObject,ByVal e As TreeListCommandEventArgs)Handles RadTreeList1.UpdateCommand
'Canceling out the automatic data source operation (needed if you use a data source control)
e.Canceled =True'Using the ExtractValuesFromItem() method to get hold of the edited valuesDim newValues AsNewSystem.Collections.Specialized.OrderedDictionary()Dim editedItem As TreeListEditableItem =CType(e.Item, TreeListEditableItem)
e.Item.OwnerTreeList.ExtractValuesFromItem(newValues, editedItem,True)'Updating logic follows, this part depends on your own custom way of performing CRUD operations
SqlDataSource1.UpdateParameters("EmployeeID").DefaultValue = newValues("EmployeeID").ToString()
SqlDataSource1.UpdateParameters("LastName").DefaultValue = newValues("LastName").ToString()
SqlDataSource1.UpdateParameters("FirstName").DefaultValue = newValues("FirstName").ToString()
SqlDataSource1.UpdateParameters("Title").DefaultValue = newValues("Title").ToString()
SqlDataSource1.UpdateParameters("HireDate").DefaultValue = newValues("HireDate").ToString()
SqlDataSource1.Update()'Closing the edit form and rebinding the treelist control
RadTreeList1.EditIndexes.Clear()
RadTreeList1.Rebind()EndSub
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.
protectedvoidRadTreeList2_UpdateCommand(object sender,Telerik.Web.UI.TreeListCommandEventArgs e){//Canceling out the automatic data source operation (needed if you use a data source control)
e.Canceled =true;//Accessing the DataKeyValue of the edited item, which is used to recognize the edited row in the data sourceTreeListEditFormItem editedItem =(e.Item asTreeListEditFormItem);string dataKeyValue = editedItem.ParentItem.GetDataKeyValue("EmployeeID").ToString();//For InPlace editing, these two lines would be://TreeListDataItem editedItem = (e.Item as TreeListDataItem);//string dataKeyValue = editedItem.GetDataKeyValue("EmployeeID");//Accessing the values of the edited item through the column editorsstring lastName =(editedItem.GetColumnEditor("LastName")asTreeListTextBoxColumnEditor).TextBoxControl.Text;string firstName =(editedItem.GetColumnEditor("FirstName")asTreeListTextBoxColumnEditor).TextBoxControl.Text;string title =(editedItem.GetColumnEditor("Title")asTreeListTextBoxColumnEditor).TextBoxControl.Text;DateTime? hireDate =(editedItem.GetColumnEditor("HireDate")asTreeListDateTimeColumnEditor).DatePickerControl.SelectedDate;//Updating logic follows, this part depends on your own custom way of performing CRUD operations
SqlDataSource1.UpdateParameters["EmployeeID"].DefaultValue = dataKeyValue;
SqlDataSource1.UpdateParameters["LastName"].DefaultValue = lastName;
SqlDataSource1.UpdateParameters["FirstName"].DefaultValue = firstName;
SqlDataSource1.UpdateParameters["Title"].DefaultValue = title;
SqlDataSource1.UpdateParameters["HireDate"].DefaultValue = hireDate.ToString();
SqlDataSource1.Update();//Closing the edit form and rebinding the treelist control
RadTreeList2.EditIndexes.Clear();
RadTreeList2.Rebind();}
VB.NET
ProtectedSub RadTreeList1_UpdateCommand(ByVal sender AsObject,ByVal e As Telerik.Web.UI.TreeListCommandEventArgs)Handles RadTreeList1.UpdateCommand
'Canceling out the automatic data source operation (needed if you use a data source control)
e.Canceled =True'Accessing the DataKeyValue of the edited item, which is used to recognize the edited row in the data sourceDim editedItem As TreeListEditFormItem =CType(e.Item, TreeListEditFormItem)Dim dataKeyValue AsString= editedItem.ParentItem.GetDataKeyValue("EmployeeID").ToString()'For InPlace editing, the last two lines would be:'Dim editedItem As TreeListDataItem = CType(e.Item, TreeListDataItem)'Dim dataKeyValue As String = editedItem.GetDataKeyValue("EmployeeID")'Accessing the values of the edited item through the column editorsDim lastName AsString=CType(editedItem.GetColumnEditor("LastName"), TreeListTextBoxColumnEditor).TextBoxControl.TextDim firstName AsString=CType(editedItem.GetColumnEditor("FirstName"), TreeListTextBoxColumnEditor).TextBoxControl.TextDim title AsString=CType(editedItem.GetColumnEditor("Title"), TreeListTextBoxColumnEditor).TextBoxControl.TextDim hireDate AsSystem.Nullable(Of DateTime)=CType(editedItem.GetColumnEditor("HireDate"), TreeListDateTimeColumnEditor).DatePickerControl.SelectedDate
'Updating logic follows, this part depends on your own custom way of performing CRUD operations
SqlDataSource1.UpdateParameters("EmployeeID").DefaultValue = dataKeyValue
SqlDataSource1.UpdateParameters("LastName").DefaultValue = lastName
SqlDataSource1.UpdateParameters("FirstName").DefaultValue = firstName
SqlDataSource1.UpdateParameters("Title").DefaultValue = title
SqlDataSource1.UpdateParameters("HireDate").DefaultValue = hireDate.ToString()
SqlDataSource1.Update()'Closing the edit form and rebinding the treelist control
RadTreeList1.EditIndexes.Clear()
RadTreeList1.Rebind()EndSub