This is a migrated thread and some comments may be shown as answers.

Treeview in dynamic usercontrol collapsed after nodeclick

1 Answer 37 Views
XmlHttpPanel
This is a migrated thread and some comments may be shown as answers.
Quan Nguyen
Top achievements
Rank 1
Quan Nguyen asked on 15 Jul 2010, 08:50 PM
Hi,
I am having following problem when using RadTreeView within a WebUserControl which is dynamically loaded on a main aspx page. I use ExpandeMode=TreeNodeExpandMode.ServerSideCallBack for node expand event. The tree, whose root nodes are loaded within OnPreRender, keep getting rebuilt everytime i do NodeClick to load a RadGrid data. Is there a different place that I can put the code to built the tree  roots so it do not get refreshed within OnPreRender event.
Below are my source codes:
.vb

Partial

 

Class Controls_DocumentInquiry_BatchDetails

 

 

Inherits ContentControl

 

 

 

 

 

 

 

Protected Overrides Sub OnPreRender(ByVal e As EventArgs)

 

 

MyBase.OnPreRender(e)

 

 

If Not IsPostBack Then

 

 

 

 

 

End If

 

 

 

 

 

If StageName <> "" Then

 

 

 

 

 

Dim dsScanMainBatches As DataSet = ScanMainData

 

 

Dim dsBatchMainBatches As DataSet = batchmainData

 

 

Dim dsStages As DataSet = AllStagesData

 

 

Dim drStage() As DataRow

 

 

For Each dt As DataTable In dsStages.Tables

 

drStage = dt.Select(

"StageID = " & StageID)

 

 

If drStage.Length > 0 Then

 

 

 

 

 

Exit For

 

 

 

 

 

End If

 

 

 

 

 

Next

 

 

 

 

LoadRootNodes(rtvBatches, TreeNodeExpandMode.ServerSideCallBack, StageName, drStage, dsScanMainBatches, dsBatchMainBatches)

 

End If

 

 

 

 

 

End Sub

 

 

 






Protected
Sub Page_Load(ByVal source As Object, ByVal e As EventArgs)

 

 

 

End Sub

 

 

 

 

 

 

Protected Sub Page_Init(ByVal source As Object, ByVal e As EventArgs)

 

 

End Sub

 

 

 

 

 

 

Protected Sub rgBatchDetails_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rgBatchDetails.SelectedIndexChanged

 

 

'Display the image

 

 

 

 

 

 

Dim strBatchNumber As String = rgBatchDetails.SelectedItems(0).Cells(2).Text

 

 

Dim strImageFile As String = rgBatchDetails.SelectedItems(0).Cells(3).Text

 

GridImageDetails.LoadData(

"Image.aspx?ImageLocation=C:\CMMain\CMData\Output\" & strBatchNumber & "\" & strImageFile)

 

 

End Sub

 

 

 

 

 

 

 

Protected Sub rtvBatches_NodeClick(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs)

 

rgBatchDetails.Rebind()

 

End Sub

 

 

 

 

 

 

Public Function GetBatchViewData(ByVal nodeSelected As RadTreeNode) As DataSet

 

 

Dim ds As New DataSet

 

 

If nodeSelected.Value.Substring(0, 4) = "BATC" Then

 

 

 

 

 

ds = objRTLWebService.Retrieve_DocumentsByBatch(nodeSelected.Text, strError)

 

ElseIf nodeSelected.Value.Substring(0, 4) = "GROU" Then

 

 

 

 

 

ds = objRTLWebService.Retrieve_DocumentsByGroup(nodeSelected.ParentNode.Text, nodeSelected.Text, strError)

 

ElseIf nodeSelected.Text = "OPEN/PENDING" Then

 

 

 

 

 

 

End If

 

 

 

 

 

 

Return ds

 

 

End Function

 

 

 

 

 

 

Private Function CreateNode(ByVal strName As String, ByVal isExpanded As Boolean) As RadTreeNode

 

 

Dim node As New RadTreeNode(strName)

 

node.Expanded = isExpanded

 

Return node

 

 

End Function

 

 

 

 

 

 

Private Shared Sub LoadRootNodes(ByVal treeBatches As RadTreeView, ByVal expandMode As TreeNodeExpandMode, _

 

 

ByVal strStageName As String, ByVal drStage() As DataRow, _

 

 

ByVal dsScanMainBatches As DataSet, ByVal dsBatchMainBatches As DataSet)

 

 

If drStage.Length = 0 Then

 

 

 

 

 

 

Dim a = 0

 

 

Exit Sub

 

 

 

 

 

 

Else

 

 

 

 

 

treeBatches.Nodes.Clear()

 

Dim intCounter1 As Integer = 0

 

 

Dim intCounter2 As Integer = 0

 

 

Dim strOpenStatus As String = drStage(0).Item("OpenStatus").ToString

 

 

Dim strInProgressStatus As String = drStage(0).Item("InProgressStatus").ToString

 

 

Dim strCompleteStatus As String = drStage(0).Item("CompleteStatus").ToString

 

 

If strStageName = "SCANNING" Then

 

 

 

 

 

 

Dim drOpen() As DataRow = dsScanMainBatches.Tables(0).Select("BatchStatus = '" & strOpenStatus & "'")

 

 

Dim drInProgress() As DataRow = dsScanMainBatches.Tables(0).Select("BatchStatus = '" & strInProgressStatus & "'")

 

 

Dim drComplete() As DataRow = dsScanMainBatches.Tables(0).Select("BatchStatus = '" & strCompleteStatus & "'")

 

intCounter1 = drOpen.Length + drInProgress.Length

intCounter2 = drComplete.Length

 

Else

 

 

 

 

 

 

Dim drOpen() As DataRow = dsBatchMainBatches.Tables(0).Select("BatchStatus = '" & strOpenStatus & "'")

 

 

Dim drInProgress() As DataRow = dsBatchMainBatches.Tables(0).Select("BatchStatus = '" & strInProgressStatus & "'")

 

 

Dim drComplete() As DataRow = dsBatchMainBatches.Tables(0).Select("BatchStatus = '" & strCompleteStatus & "'")

 

intCounter1 = drOpen.Length + drInProgress.Length

intCounter2 = drComplete.Length

 

End If

 

 

 

 

 

 

Dim node As New RadTreeNode()

 

node.Text =

"Open/Pending" & "(" & intCounter1.ToString() & ")"

 

 

 

 

 

node.Value =

"0" & strStageName

 

node.ToolTip =

"ROOT"

 

 

 

 

 

 

If intCounter1 > 0 Then

 

 

 

 

 

node.ExpandMode = expandMode

 

End If

 

 

 

 

 

treeBatches.Nodes.Add(node)

 

Dim node1 As New RadTreeNode()

 

node1.Text =

"Complete" & "(" & intCounter2.ToString() & ")"

 

 

 

 

 

node1.Value =

"1" & strStageName

 

node1.ToolTip =

"ROOT"

 

 

 

 

 

 

If intCounter2 > 0 Then

 

 

 

 

 

node1.ExpandMode = expandMode

 

End If

 

 

 

 

 

treeBatches.Nodes.Add(node1)

 

End If

 

 

 

 

 

 

End Sub

 

 

 

 

 

 

Protected Sub rtvBatches_NodeExpand(ByVal sender As Object, ByVal e As RadTreeNodeEventArgs)

 

 

Dim dsScanMainBatches As DataSet = ScanMainData

 

 

Dim dsBatchMainBatches As DataSet = batchmainData

 

 

Dim dsStages As DataSet = AllStagesData

 

 

Dim drStage() As DataRow

 

 

For Each dt As DataTable In dsStages.Tables

 

drStage = dt.Select(

"StageID = " & StageID)

 

 

If drStage.Length > 0 Then

 

 

 

 

 

 

Exit For

 

 

 

 

 

 

End If

 

 

 

 

 

 

Next

 

 

 

 

 

PopulateNodeOnDemand(e, TreeNodeExpandMode.ServerSideCallBack, dsScanMainBatches, dsBatchMainBatches, drStage)

 

End Sub

 

 

 

 

 

 

Private Shared Sub PopulateNodeOnDemand(ByVal e As RadTreeNodeEventArgs, ByVal expandMode As TreeNodeExpandMode, _

 

 

ByVal dsScanMainBatches As DataSet, ByVal dsBatchMainBatches As DataSet, _

 

 

ByVal drStage() As DataRow)

 

 

Dim strNodeText As String = e.Node.Text

 

 

Dim strNodeValue As String = e.Node.Value

 

 

Dim strStageName As String = strNodeValue.Substring(1, strNodeValue.Length - 1)

 

 

If drStage.Length = 0 Then

 

 

 

 

 

 

Dim a = 0

 

 

Exit Sub

 

 

 

 

 

 

Else

 

 

 

 

 

 

Dim dtData As New DataTable

 

 

If strNodeText.ToUpper.IndexOf("OPEN/PENDING") >= 0 Then

 

 

 

 

 

 

If strStageName = "SCANNING" Or strStageName = "" Then

 

 

 

 

 

dtData = dsScanMainBatches.Tables(0)

 

Else

 

 

 

 

 

dtData = dsBatchMainBatches.Tables(0)

 

End If

 

 

 

 

 

 

Dim drData() As DataRow = dtData.Select("BatchStatus = '" & drStage(0).Item("OpenStatus") & "'")

 

 

For Each row As DataRow In drData

 

 

Dim node As New RadTreeNode()

 

node.Text = row(

"BatchNumber").ToString()

 

node.Value =

"BATCH" & row("BatchNumber").ToString()

 

node.ExpandMode = expandMode

e.Node.Nodes.Add(node)

 

Next

 

 

 

 

 

e.Node.Expanded =

True

 

 

 

 

 

 

ElseIf strNodeText.ToUpper.IndexOf("COMPLETE") >= 0 Then

 

 

 

 

 

 

If strStageName = "SCANNING" Then

 

 

 

 

 

dtData = dsScanMainBatches.Tables(0)

 

Else

 

 

 

 

 

dtData = dsBatchMainBatches.Tables(0)

 

End If

 

 

 

 

 

 

Dim drData() As DataRow = dtData.Select("BatchStatus = '" & drStage(0).Item("CompleteStatus") & "'")

 

 

For Each row As DataRow In drData

 

 

Dim node As New RadTreeNode()

 

node.Text = row(

"BatchNumber").ToString()

 

node.Value =

"BATCH" & row("BatchNumber").ToString()

 

node.ExpandMode = expandMode

e.Node.Nodes.Add(node)

 

Next

 

 

 

 

 

e.Node.Expanded =

True

 

 

 

 

 

 

ElseIf strNodeValue.Substring(0, 4) = "BATC" Then

 

 

 

 

 

dtData = GetGroupNodes(strNodeText)

 

For Each row As DataRow In dtData.Rows

 

 

Dim node As New RadTreeNode()

 

node.Text = row(

"DocTypeIndex").ToString("000")

 

node.Value =

"GROUP" & row("DocTypeIndex").ToString()

 

 

If dtData.Rows.Count > 0 Then

 

 

 

 

 

node.ExpandMode = expandMode

 

End If

 

 

 

 

 

e.Node.Nodes.Add(node)

 

Next

 

 

 

 

 

e.Node.Expanded =

True

 

 

 

 

 

 

ElseIf strNodeValue.Substring(0, 4) = "GROU" Then

 

 

 

 

 

dtData = GetDocumentNodes(e.Node.ParentNode.Text, strNodeText)

 

For Each row As DataRow In dtData.Rows

 

 

Dim node As New RadTreeNode()

 

node.Text = row(

"DocType").ToString & " " & row("ImageFile").ToString & " " & row("AccountNo").ToString & " " & row("Amount").ToString

 

node.Value =

"DOC" & row("ImageFile").ToString()

 

 

If dtData.Rows.Count > 0 Then

 

 

 

 

 

node.ExpandMode = expandMode

 

End If

 

 

 

 

 

e.Node.Nodes.Add(node)

 

Next

 

 

 

 

 

e.Node.Expanded =

True

 

 

 

 

 

 

End If

 

 

 

 

 

 

End If

 

 

 

 

 

 

End Sub

 

 

 

 

 

 

Private Shared Function GetGroupNodes(ByVal strBatchNumber As String) As DataTable

 

 

Dim dsGroups As DataSet = objRTLWebService.Retrieve_GroupsByBatch(strBatchNumber, strError)

 

 

Return dsGroups.Tables(0)

 

 

End Function

 

 

 

 

 

 

Private Shared Function GetDocumentNodes(ByVal strBatchNumber As String, ByVal strGroupNumber As String) As DataTable

 

 

Dim dsDocuments As DataSet = objRTLWebService.Retrieve_DocumentsByGroup(strBatchNumber, strGroupNumber, strError)

 

 

Return dsDocuments.Tables(0)

 

 

End Function

 

1 Answer, 1 is accepted

Sort by
0
Pero
Telerik team
answered on 20 Jul 2010, 01:13 PM
Hello Quan,

I would suggest to use the IsCallback flag to check whether a callback has been initiated and then perform any code that you need executed on a callback or not.
I tried to run the code but with no success. Could you please provide a fully working code, that could be run locally without a problem? Moreover, are you using the RadXmlHttpPanel to load the control, and if yes could you provide code showing how the user control is loaded?

Kind regards,
Pero
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
XmlHttpPanel
Asked by
Quan Nguyen
Top achievements
Rank 1
Answers by
Pero
Telerik team
Share this question
or