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:
protectedvoidRadTreeList1_InsertCommand(object sender,TreeListCommandEventArgs e){//Canceling out the automatic datasource operation (needed if you use a datasource control)
e.Canceled =true;//Using the ExtractValuesFromItem() method to get hold of the newly provided valuesHashtable insertValues =newHashtable();TreeListEditableItem editedItem = e.Item asTreeListEditableItem;
e.Item.OwnerTreeList.ExtractValuesFromItem(insertValues, editedItem,false);//Inserting logic follows, this part depends on your own custom way of performing CRUD operations
SqlDataSource1.InsertParameters["LastName"].DefaultValue = insertValues["LastName"].ToString();
SqlDataSource1.InsertParameters["LastName"].DefaultValue = insertValues["LastName"].ToString();
SqlDataSource1.InsertParameters["FirstName"].DefaultValue = insertValues["FirstName"].ToString();
SqlDataSource1.InsertParameters["Title"].DefaultValue = insertValues["Title"].ToString();
SqlDataSource1.InsertParameters["HireDate"].DefaultValue = insertValues["HireDate"].ToString();
SqlDataSource1.Insert();//Closing the insert form and rebinding the treelist control (needed when the default action was canceled)
RadTreeList1.InsertIndexes.Clear();
RadTreeList1.Rebind();}
VB.NET
ProtectedSub RadTreeList1_InsertCommand(ByVal sender AsObject,ByVal e As TreeListCommandEventArgs)Handles RadTreeList1.InsertCommand
'Canceling out the automatic datasource operation (needed if you use a datasource control)
e.Canceled =True'Using the ExtractValuesFromItem() method to get hold of the newly provided valuesDim insertValues AsNew Hashtable()Dim editedItem As TreeListEditableItem =TryCast(e.Item, TreeListEditableItem)
e.Item.OwnerTreeList.ExtractValuesFromItem(insertValues, editedItem,False)'Inserting logic follows, this part depends on your own custom way of performing CRUD operations
SqlDataSource1.InsertParameters("LastName").DefaultValue = insertValues("LastName").ToString()
SqlDataSource1.InsertParameters("LastName").DefaultValue = insertValues("LastName").ToString()
SqlDataSource1.InsertParameters("FirstName").DefaultValue = insertValues("FirstName").ToString()
SqlDataSource1.InsertParameters("Title").DefaultValue = insertValues("Title").ToString()
SqlDataSource1.InsertParameters("HireDate").DefaultValue = insertValues("HireDate").ToString()
SqlDataSource1.Insert()'Closing the insert form and rebinding the treelist control
RadTreeList1.InsertIndexes.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.
protectedvoidRadTreeList2_InsertCommand(object sender,TreeListCommandEventArgs e){//Canceling out the automatic datasource operation (needed if you use a datasource control)
e.Canceled =true;//Accessing the values of the insert item through the column editorsTreeListEditableItem insertedItem = e.Item asTreeListEditableItem;string lastName =(insertedItem.GetColumnEditor("LastName")asTreeListTextBoxColumnEditor).TextBoxControl.Text;string firstName =(insertedItem.GetColumnEditor("FirstName")asTreeListTextBoxColumnEditor).TextBoxControl.Text;string title =(insertedItem.GetColumnEditor("Title")asTreeListTextBoxColumnEditor).TextBoxControl.Text;DateTime? hireDate =(insertedItem.GetColumnEditor("HireDate")asTreeListDateTimeColumnEditor).DatePickerControl.SelectedDate;//Inserting logic follows, this part depends on your own custom way of performing CRUD operations
SqlDataSource1.InsertParameters["LastName"].DefaultValue = lastName;
SqlDataSource1.InsertParameters["FirstName"].DefaultValue = firstName;
SqlDataSource1.InsertParameters["Title"].DefaultValue = title;
SqlDataSource1.InsertParameters["HireDate"].DefaultValue = hireDate.ToString();
SqlDataSource1.Insert();//Closing the insert form and rebinding the treelist control
RadTreeList2.InsertIndexes.Clear();
RadTreeList2.Rebind();}
VB.NET
ProtectedSub RadTreeList2_InsertCommand(ByVal sender AsObject,ByVal e As TreeListCommandEventArgs)'Canceling out the automatic datasource operation (needed if you use a datasource control)
e.Canceled =True'Accessing the values of the insert item through the column editorsDim insertedItem As TreeListEditableItem =TryCast(e.Item, TreeListEditableItem)Dim lastName AsString=TryCast(insertedItem.GetColumnEditor("LastName"), TreeListTextBoxColumnEditor).TextBoxControl.TextDim firstName AsString=TryCast(insertedItem.GetColumnEditor("FirstName"), TreeListTextBoxColumnEditor).TextBoxControl.TextDim title AsString=TryCast(insertedItem.GetColumnEditor("Title"), TreeListTextBoxColumnEditor).TextBoxControl.TextDim hireDate AsSystem.Nullable(Of DateTime)=TryCast(insertedItem.GetColumnEditor("HireDate"), TreeListDateTimeColumnEditor).DatePickerControl.SelectedDate
'Inserting logic follows, this part depends on your own custom way of performing CRUD operations
SqlDataSource1.InsertParameters("LastName").DefaultValue = lastName
SqlDataSource1.InsertParameters("FirstName").DefaultValue = firstName
SqlDataSource1.InsertParameters("Title").DefaultValue = title
SqlDataSource1.InsertParameters("HireDate").DefaultValue = hireDate.ToString()
SqlDataSource1.Insert()'Closing the insert form and rebinding the treelist control
RadTreeList2.InsertIndexes.Clear()
RadTreeList2.Rebind()EndSub
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.