RadTreeView cannot refresh to show changes in hierarchical data source

3 posts, 0 answers
  1. Paul Robertson
    Paul Robertson avatar
    78 posts
    Member since:
    May 2010

    Posted 13 Nov 2012 Link to this post

    Hi folks

    I have a rather serious problem trying to get a radTreeView to show changes in the underlying database and therefore datasource. My scenario is as follows.

    1. In the Load event hander, the radTreeView is initialized as in the following example code:

                    radCommentTreeView1.DataSource = Nothing
                    // Initialize custom data object from custom hierarchical data source class
                    cdsPubCommentDataSource = New CommentDataSource(1)
                    radCommentTreeView1.DataSource = cdsPubCommentDataSource

                    // Configure radTreeView from datasource fields
                    radCommentTreeView1.DataFieldID = "ID"
                    radCommentTreeView1.DataFieldParentID = "ParentID"
                    radCommentTreeView1.DataTextField = "Content"

                    // Bind radTreeView to datasource

    2. The page loads with radTreeView rendered correctly

    3. User attempts to add or delete a node by clicking a button with a server-side handler ....

    4. ... so that the postback cycle begins in the server-side code, with the Load handler from (2) above running again, to rebind the radTreeView

    5. ... only after which the server-side button handler is run, successfully running an SQL command through another BLL business object (i.e., the SQL database is successfully modified ) ....

    6. However, when the page renders after the postback, the radTreeView still reflects the original node hierarchy from (4) above, before the node was deleted in (5).

    Could someone indicate how this process ought to be achieved within the cycle of a single postback - if I try to rebind again after the button handler, none of the radTreeView nodes render properly at all, presumably because the process must occur no later than the Load handler?

    I am aware of the idea of using the INotifyPropertyChanged interface for the datasource object, and already have the event in question being successfully fired up from the DataSource object, namely a PropertyChanged event indicating a change in the DataSourceView object, but I am not sure how a PropertyChanged event handler can help in the scenario I describe - the PropertyChanged event handler in the page is still invoked before the button handler, and so the database has not been changed at the time the event handler runs. Is the PropertyChanged event the correct way forward, or is there another approach better suited for refreshing the radTreeView within a single postback cycle?

    Thanks if someone can point me in the right direction with this problem.


  2. Paul Robertson
    Paul Robertson avatar
    78 posts
    Member since:
    May 2010

    Posted 16 Nov 2012 Link to this post

    Hi there

    I really do need to get some guidance with this.

    I think the heart of the problem is that: if I call DataBind on the radTreeView at the end of the server-side button handler, this does seem to pick up the database changes, but unfortunately it destroys the radTreeView's formatting with the node template, and as a result, no node databound content is rendered in any of the nodes. Obviously, the node template needs to be instantiated at the start of the page life-cycle, and if, as in this case, databinding late in the cycle disrupts the template, I cannot tell the page to 'go back' and instantiate the template again. What possible work around can there be to this issue?

    I tried going down the 'postbackeventreference' route, to trigger a second postback, but this is very inelegant, and quite unsatisfactory, as it triggers the 'Resend' dialog box in the browser, although afterwards the new database content is shown correctly.

    Is this a bug in the way the control handles its node template?


  3. Plamen
    Plamen avatar
    2818 posts

    Posted 16 Nov 2012 Link to this post

    Hi Paul,

    The scenario you describe is not quite clear- basically we recommend almost the same you are doing making the change in the DataSource and DataBinding RadTreeView at the end of the button click event. If you are trying to use templates at the same time you can refer to this help topic where the recommended way of adding them at runtime is explained. 

    hope this will be helpful.

    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