Server-side (Dynamic) Creation of Treeview inside Combobox inside Toolbar

2 posts, 0 answers
  1. Tomas
    Tomas avatar
    3 posts
    Member since:
    Sep 2012

    Posted 11 Apr 2013 Link to this post

    Consider:

    I am dynamically creating a toolbar that has a RadComboBox button, such that I do the following:

    ' in the page_load:
     
    If Not m_ThisPage.IsPostBack Then
       Dim btnSearchByTxt As New RadToolBarButton()
       btnSearchByTxt.Text = "SearchFor"
       btnSearchByTxt.Value = "searchfor"
       m_RadToolBar.Items.Add(btnSearchByTxt)
     
       InstantiateSearch()
       Dim cboSearchItem As RadToolBarItem = m_RadToolBar.FindItemByText("SearchFor")
       Dim cboSearchBox As RadComboBox = CType(cboSearchItem.FindControl("SearchComboBox"), RadComboBox)
       AddHandler cboSearchBox.SelectedIndexChanged, AddressOf cboSearchBox_SelectedIndexChanged
     
    End If
     
    ' -------------- snip ----------------
     
        Private Sub InstantiateSearch()
     
            Dim searchTemplate As New ComboBoxSearchTemplate
            Dim cboSearchItem As RadToolBarItem = m_RadToolBar.FindItemByText("SearchFor")
            'Dim searchTemplate2 As New TextBoxSearchTemplate()
            'Dim textSearchItem As RadToolBarItem = m_RadToolBar.FindItemByText("SearchFor")
            If TypeOf cboSearchItem Is RadToolBarButton Then
                searchTemplate.InstantiateIn(cboSearchItem)
            End If
     
            m_RadToolBar.DataBind()
     
        End Sub
     
        Private Class ComboBoxSearchTemplate
     
            Implements ITemplate
     
            Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
     
                Dim cboBox1 As New RadComboBox()
     
                cboBox1.ID = "SearchComboBox"
                cboBox1.DropDownWidth = 460
                cboBox1.Sort = RadComboBoxSort.Ascending
                cboBox1.SortCaseSensitive = False
                'cboBox1.DropDownCssClass = "searchDropDown"
                cboBox1.AllowCustomText = True
                cboBox1.AutoPostBack = True
                cboBox1.EmptyMessage = "Search for..."
                cboBox1.EnableItemCaching = True
                cboBox1.EnableLoadOnDemand = True
                cboBox1.MaxHeight = 320
                cboBox1.MaxLength = 2999
                cboBox1.Width = 250
                cboBox1.ExpandDelay = 2500
                cboBox1.LoadingMessage = "Searching..."
                cboBox1.Attributes.Add("onitemsrequested", "SearchComboBox_ItemsRequested")
                'cboBox1.Attributes.Add("onkeydown", "fire()")
                cboBox1.OnClientKeyPressing = "fire"
                cboBox1.CloseDropDownOnBlur = False
                cboBox1.Text = ""
                cboBox1.Font.Size = 9
                cboBox1.Font.Bold = False
                cboBox1.Font.Name = "Sans-Serif"
     
                cboBox1.DataTextField = "CMM_DESCRIPTION"
                cboBox1.Items.Add(New RadComboBoxItem(""))
     
                Dim ctt As ComboBoxTreeTemplate = New ComboBoxTreeTemplate
                ctt.InstantiateIn(cboBox1.Items(0))
     
                AddHandler cboBox1.DataBinding, AddressOf cboBox1_DataBinding
                AddHandler cboBox1.ItemsRequested, AddressOf cboBox1_ItemsRequested
                cboBox1.DataBind()
     
                container.Controls.Add(cboBox1)
     
            End Sub
     
        End Class
     
        Private Class ComboBoxTreeTemplate
     
            Implements ITemplate
     
            Public Sub InstantiateIn(ByVal container As Control) Implements ITemplate.InstantiateIn
     
                Dim rtv As RadTreeView = New RadTreeView()
     
                rtv.ID = "RadTreeView1"
                rtv.Skin = "Telerik"
                rtv.SingleExpandPath = True
     
                rtv.DataTextField = "CMM_DESCRIPTION"
                rtv.DataValueField = "CMM_ID"
                rtv.DataFieldParentID = "CMM_PARENT_ID"
     
                Dim sProc As String = "sptMaterialInventory_AddEdit_GetCommodity"
                Dim connection As New SqlConnection(ConfigurationManager.ConnectionStrings("TRACURATEConnectionString").ConnectionString)
                Dim adapter As New SqlDataAdapter(sProc, connection)
                adapter.SelectCommand.CommandType = CommandType.StoredProcedure
                Dim dataTable As New DataTable()
                adapter.Fill(dataTable)
                rtv.DataSource = dataTable
                rtv.DataBind()
                container.Controls.Add(rtv)
     
            End Sub
     
        End Class

    The idea is that I want to populate the combobox in the toolbar, with a treeview.  First, for some reason, the treeview is flat.  If I use the same stored procedure in a treeview that I create in ASPX, it renders perfectly.  Using the exact same in this dynamic fashion, there are no parents/children.  Just a flat list of all nodes.

    Second: the treeview is fine the first rendering of the page.  When an AJAX post-back occurs, I get an error stating that the treeview does not exist.

    I am looking for two answers:

    1) How do I get the full treeview with parent/children to render?
    2) How do I cause the treeview to not disappear after the first AJAX post-back?

    I hope that this is enough code for you to understand what I am doing.

    Thank you,

    Tomas

  2. Tomas
    Tomas avatar
    3 posts
    Member since:
    Sep 2012

    Posted 11 Apr 2013 Link to this post

    I've attached a screen shot of the error that I receive after/during a post-back (AJAX).
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top