Inserting / Editing position of items in the TreeList

4 posts, 1 answers
  1. Paul
    Paul avatar
    29 posts
    Member since:
    Aug 2011

    Posted 21 Sep 2011 Link to this post

    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?
  2. Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 27 Sep 2011 Link to this post

    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
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Paul
    Paul avatar
    29 posts
    Member since:
    Aug 2011

    Posted 27 Sep 2011 Link to this post

    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?
  5. Answer
    Tsvetina
    Admin
    Tsvetina avatar
    1873 posts

    Posted 28 Sep 2011 Link to this post

    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
Back to Top