This is a migrated thread and some comments may be shown as answers.

Inserting / Editing position of items in the TreeList

3 Answers 84 Views
TreeList
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 21 Sep 2011, 03:46 PM
I am trying to insert/edit items in the TreeList using a pop-up template. The item’s fields being modified have no relation to its parent and the order under its parent is not in a predetermined order, but determined by the person performing the modification and must be maintained.
The inserting and update of the data source is handled manually. I’m trying to use as little server resources as possible. For the edit I can include the DataIndex as a bound field and get the value back in the UpdateCommand event. This does not work when inserting new items in the TreeList. In the ItemCreated, I can get the DataIndex and save it in a protected variable and reference it from the pop-up, but it is not passed back for the InsertCommand, it is not bound.
Any ideas on how the determine the DataIndex of the item which caused the pop-up for the insert/edit?

3 Answers, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 27 Sep 2011, 08:22 AM
Hello Paul,

I am not sure exactlywhich DataIndex you have in mind, is it the DataItemIndex of the edited item? If so, you can access the parent item of the (popup) edit form and take its index:
Insert:
protected void RadTreeList1_InsertCommand(object sender, TreeListCommandEventArgs e)
{
    TreeListDataItem item = (e.Item as TreeListEditFormInsertItem).ParentItem as TreeListDataItem;
    if(item!=null) //if the ParentItem is null, then we are inserting a root item
    int index = item.DataItemIndex;
}

Update:
protected void RadTreeList1_UpdateCommand(object sender, TreeListCommandEventArgs e)
{
    TreeListDataItem item = (e.Item as TreeListEditFormItem).ParentItem as TreeListDataItem;
    int index = item.DataItemIndex;
}

Best wishes,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
0
Paul
Top achievements
Rank 1
answered on 27 Sep 2011, 01:14 PM
Thanks for the response.
I was looking for the DataItemIndex, sequence number of the data row of the entire record set, for the item clicked. The code ParentItem.DataItemIndex is returning the sequence number of the displayed data, not the record set sequence number. I didn’t like doing it, but I added the record set sequence number to the record set and bound it to a column zero pixels wide. I now use item.ParentItem.Cells to get the record set sequence number.
Is there a way to get the record set sequence number as long as you don’t use the AllowLoadOnDemand?
0
Accepted
Tsvetina
Telerik team
answered on 28 Sep 2011, 12:11 PM
Hello Paul,

RadTreeList does not keep the index of its record inside the control's datasource, so some custom approach like the one you use is needed in order to obtain this information. However, one thing to consider is to use the DataKeyValue of the row in order to locate the corresponding record inside the treelist's datasource.

Greetings,
Tsvetina
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
TreeList
Asked by
Paul
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Paul
Top achievements
Rank 1
Share this question
or