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

[Solved] Get parent node in controller action

3 Answers 92 Views
TreeView
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Donna Stewart
Top achievements
Rank 1
Donna Stewart asked on 11 Mar 2011, 05:35 PM
How do I get the parent node value in the controller action for the load on demad ajax binding?  I have tried node.Parent, but it is nothing/null/empty.  Also, setting the content of the node is not working, and I know it is getting populated with the html, so any advice you can give there is very much appreciated as well.  Thank you so much for your help!

Donna

Here's the treeview:
<%= Html.Telerik().TreeView().Name("ReportGroups").ShowCheckBox(True).HtmlAttributes(New With {.style = "font-size:1em; height:550px;"}) _
                                                .ClientEvents(Function(evt) evt.OnSelect("getReports")) _
                                                .ClientEvents(Function(evt) evt.OnLoad("setContextMenu")) _
                                                .ClientEvents(Function(evt) evt.OnDataBound("onTreeViewLoad")) _
                                                .ClientEvents(Function(evt) evt.OnCollapse("updateTreeViewState")) _
                                                .ClientEvents(Function(evt) evt.OnExpand("updateTreeViewState")) _
    .BindTo(CType(Model.reportGroupNames, IEnumerable(Of SelectListItem)),
        Sub(mappings)
            mappings.For(Of SelectListItem)(
            Sub(binding)
                binding _
                    .ItemDataBound(
                        Sub(item, rpt)
                            Dim isExpanded As Boolean = DirectCast(ViewData("ExpandedNodes"), String()).Contains(rpt.Text)
                            If isExpanded Then
                                item.Text = "<span class='expanded'></span>" + rpt.Text
                            Else
                                item.Text = rpt.Text
                            End If
                            item.Value = rpt.Value
                            item.LoadOnDemand = True
                        End Sub)
            End Sub)
        End Sub) _
    .DataBinding(Function(dataBinding) dataBinding.Ajax().Select("GetUserGroupsForReportGroups", "Report"))
%>

Here's the controller action code (I have bolded the line of code in question - it has been commented out in the code so it is in green):
<AcceptVerbs(HttpVerbs.Post)> _
Function GetUserGroupsForReportGroups(ByVal node As TreeViewItem) As ActionResult
    Try
        Dim gmcPermissions As New GMCPermissions
        Dim groupNameKey As Integer = node.Value.Substring(node.Value.IndexOf(".") + 1)
        Dim nodes As New List(Of TreeViewItem)
        If node.Value.Substring(0, node.Value.IndexOf(".")).Equals("report") Then
            Dim usrGrps As List(Of WebUserGroupName) = gmcPermissions.GetWebUserGroupNamesForReportGroupName(groupNameKey)
            For Each usrGrp In usrGrps
                nodes.Add(New TreeViewItem With {.Text = "<span style='font-size:.9em;'>" + usrGrp.UserGroupName + "</span>",
                                                 .Value = "usergroup." + usrGrp.UserGroupNameKey.ToString, .LoadOnDemand = True, .Encoded = False})
            Next
        Else
            '                Dim ugRptInfoList As List(Of GMCListItem) = gmcPermissions.GetReportTypesForUserGroupName(node.Parent.Value.Substring(node.Parent.Value.IndexOf(".") + 1), groupNameKey)
            Dim ugRptInfoList As List(Of GMCListItem) = gmcPermissions.GetReportTypesForUserGroupName(48, groupNameKey)
            Dim taskInfo As String
            For Each ugRptType In ugRptInfoList
                taskInfo = If(NullS(ugRptType.dataObject).Equals(""), "", "%><ul><li>" + ugRptType.dataObject + "</li></ul><%")
                nodes.Add(New TreeViewItem With {.Text = "<span style='font-size:.9em;'>" + ugRptType.key + " " + ugRptType.value + "</span>", .Value = ugRptType.dataTag, .Encoded = False, .Content = Function() taskInfo})
            Next
        End If
        Return New JsonResult With {.Data = nodes}
    Catch
        Return View("Error")
    End Try
End Function

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 14 Mar 2011, 07:48 AM
Hello Donna Stewart,

 Both are not supported. Only the currently expanded node is being send to the action method. Also modifying the expanding node has no effect. You can only return child nodes.

Regards,
Atanas Korchev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
Donna Stewart
Top achievements
Rank 1
answered on 14 Mar 2011, 03:44 PM
Hi,

Thank you for your response.  First of all, is there any plan to add the functionality to get the Parent node in this scenario since you have it as a property on the TreeViewItem?  Second, I am not trying to modify the expanding node.  I am trying to set content on the new child nodes -
                nodes.Add(New TreeViewItem With {.Text = "<span style='font-size:.9em;'>" + ugRptType.key + " " + ugRptType.value + "</span>", .Value = ugRptType.dataTag, .Encoded = False, .Content = Function() taskInfo})


However, since I can't get the parent node using on demand, then I will have to figure out another way to do what I am trying to do.

Thanks,
Donna
0
Atanas Korchev
Telerik team
answered on 15 Mar 2011, 05:10 PM
Hello Donna Stewart,

 No, we currently don't plan to do that as we would have to submit the whole treeview then. If we provide the parent node we should provide the parent node's parent, sibling nodes etc.

Regards,
Atanas Korchev
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
Tags
TreeView
Asked by
Donna Stewart
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Donna Stewart
Top achievements
Rank 1
Share this question
or