DropDownList in TreeListTemplateColumn loses selected value on Expand/Collapse

4 posts, 0 answers
  1. Lynne
    Lynne avatar
    25 posts
    Member since:
    Oct 2010

    Posted 03 Apr 2014 Link to this post

    I have a simple RadTreeList containing a BoundColumn and a TemplateColumn of type dropdownlist. I've populated the DDL dynamically for each row. The treelist displays perfectly, but when I select a value from the dropdown list on one or more rows, then collapse/expand the tree node, the values selected in the DDLs are lost. I think it is probably due to data binding.   

    The intent is for the user to a select a value from the DDL for each row in the TreeList then save the values to the database once they are finished.  I want them to be able to expand/collapse tree nodes during this process without losing the values.  I've searched through the forum and read much of the documentation online, but I would appreciate some insight into the best approach for solving this issue.  Thanks in advance. 
     
     
    <telerik:RadTreeList ID="RadTreeList1" runat="server" 
        AutoGenerateColumns="False" 
        DataKeyNames="Node" ParentDataKeyNames="ParentNode" OnItemDataBound="RadTreeList1_ItemDataBound" 
        OnItemCommand="RadTreeList1_ItemCommand" EditMode="InPlace" OnItemCreated="RadTreeList1_ItemCreated"
        ViewStateMode="Enabled">
         
        <Columns>
          <telerik:TreeListBoundColumn DataField="Description" UniqueName="Description" HeaderStyle-Width="500px"
            </telerik:TreeListBoundColumn
            <telerik:TreeListTemplateColumn UniqueName="Response"
                <ItemTemplate
                    <asp:DropDownList ID="ddl" runat="server">
                    </asp:DropDownList>
                </ItemTemplate>
          </telerik:TreeListTemplateColumn>
        </Columns>
        </telerik:RadTreeList>
  2. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 08 Apr 2014 Link to this post

    Hello Lynne,

    Can you please specify how the treelist control is populated? If you are using simple data-binding calling DataBind() you will need to assign data-source and rebind the grid after each operation (expanding/collapsing, paging, sorting, etc.). If this is the case, I would recommend you handle NeedDataSource event, prepare the data source (list of objects) for Telerik RadTreeList and assign it to the treelist's DataSource property. Give this suggestions a try and let me know about the result.

    Regards,
    Pavlina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Lynne
    Lynne avatar
    25 posts
    Member since:
    Oct 2010

    Posted 09 Apr 2014 in reply to Pavlina Link to this post

    Hi Pavlina,

    I finally found a post that answered my question. The post states "since on expand and collapse the treelist is rebound and its items are recreated, you would need to manually persist your custom selection.  You could recognize the items by DataKeyValue and use it to keep their selection in a collection in the Session or the ViewState."  The post pertained to checkboxes but I would need to do the same for my dropdownlist whose values are getting wiped out on postback. In the meantime, I was experimenting with RadTreeView and it does not appear to postback on expand/collapse so I think I'll try to use it instead of RadTreeList.  Thanks.    
  5. Pavlina
    Admin
    Pavlina avatar
    6084 posts

    Posted 14 Apr 2014 Link to this post

    Hello Lynne,

    In case you decide to use RadTreeList as you said you should first recognize the items by DataKeyValue. Then inside DropDownList OnSelectedIndexChange event you could save the selected value and OnPreRender event of the DropDownList control persist these values.

    Regards,
    Pavlina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top