1

I have a rather serious problem trying to get a Telerik 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
            radCommentTreeView1.DataBind()
    
  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 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. But calling DataBind at the end of the handler would seem to me to be the intuitively correct way to approach the issue, it's just that the resulting loss of the node template prevents it from working.

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 that is fired at (4) when the radTreeView first rebinds on the postback, 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 that stage. 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.

Regards

4

0 回答 0