RadTreeList Template Column with DropDownList Loses Value on Postback

2 posts, 0 answers
  1. Nader
    Nader avatar
    4 posts
    Member since:
    Oct 2014

    Posted 30 Jan 2015 Link to this post

    I have a RadTreeList that contains a Template Column holding a DropDownlist.  I am populating the DropDownList during the ItemDataBound event:

    Protected Sub RadTreeList1_ItemDataBound(sender As Object, e As TreeListItemDataBoundEventArgs) Handles RadTreeList1.ItemDataBound
    If TypeOf e.Item Is TreeListEditableItem AndAlso CType(e.Item, TreeListEditableItem).IsInEditMode Then
    Dim tmpItem As TreeListEditableItem = TryCast(e.Item, TreeListEditableItem)
    Dim tmpControl As MultiView = TryCast(e.Item.FindControl("MultiView1"), MultiView)

    Select Case tmpItem.DataItem("SelectionType").ToString
    Case "DROPDOWN"
    tmpControl.ActiveViewIndex = 0
    Dim tmpDrop As DropDownList = TryCast(tmpControl.FindControl("DropDownList1"), DropDownList)

    Using dbContext As New EntitiesModel
    Dim tmpInt As Integer = tmpItem.DataItem("SowGroupID")
    tmpDrop.AutoPostBack = True
    tmpDrop.DataValueField = "SowSelectionID"
    tmpDrop.DataTextField = "SelectionName"
    tmpDrop.DataSource = dbContext.LibSOWSelections.Where(Function(c) c.SowGroupID = tmpInt).OrderBy(Function(c) c.Seq_No).ToList
    End Using
    Case "CHECKBOX"
    tmpControl.ActiveViewIndex = 1
    Case "TEXTBOX"
    tmpControl.ActiveViewIndex = 2
    Case Else
    tmpControl.ActiveViewIndex = 3
    End Select
    End If
    End Sub

    This works fine, but the problem is that I have the DropDownList posting back on change so that I can perform some logic, but when it posts back, I lose the selection of the dropdownlist.  It is rebinding and I do not know where I can capture the selected value.

    Any help would be appreciated.
  2. Maria Ilieva
    Maria Ilieva avatar
    4017 posts

    Posted 04 Feb 2015 Link to this post


    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. Inside the DropDownList OnSelectedIndexChange event you could save the selected value in Session or ViewState and OnPreRender event of the DropDownList control persist these values.

    Maria Ilieva

    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