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

[Solved] DataBound Menu in VB

3 Answers 111 Views
Menu
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
John
Top achievements
Rank 2
John asked on 01 Jun 2010, 07:40 AM
Hi

I am trying to create a data bound menu in VB and not having much luck with the Lamba expression.  I am using VS2010 so multiline lambda are ok i beleive.  Below if the code and the error assciated. It appears to be almost there bit seem to be mssing soemthing. Any help would be appreciated.

John


<%= Html.Telerik().Menu() _  
            .Name("Menu") _  
            .BindTo(Model, Sub(mappings)  
                               mappings.For(Sub(binding) binding _  
                                                .itemDataBound(Sub(menuitem,category)   
                                                                   menuitem.Text = category.Name  
                                                               End Sub)    _                             
                                                .children(Sub(category) category.NavigationItems())  
                                            End Sub)  
    mappings.for(Sub(binding)  
                     .itemDataBound(Sub(menuitem, item)  
                                        menuitem.Text = item.Name  
                                    End Sub)  
                 End Sub)  
                           End Sub)  
 
%> 

Error 17 Overload resolution failed because no accessible 'BindTo' can be called with these arguments:
    'Public Function BindTo(dataSource As System.Collections.IEnumerable, factoryAction As System.Action(Of Telerik.Web.Mvc.UI.NavigationBindingFactory(Of Telerik.Web.Mvc.UI.MenuItem))) As Telerik.Web.Mvc.UI.MenuBuilder': Type parameter 'TParent' for 'Public Function For(Of TParent As Class)(action As System.Action(Of Telerik.Web.Mvc.UI.NavigationBindingBuilder(Of TNavigationItem, TParent))) As Telerik.Web.Mvc.UI.NavigationBindingFactory(Of TNavigationItem)' cannot be inferred.
    'Public Function BindTo(Of AIMSWeb.NavigationCategory)(dataSource As System.Collections.Generic.IEnumerable(Of AIMSWeb.NavigationCategory), itemDataBound As System.Action(Of Telerik.Web.Mvc.UI.MenuItem, AIMSWeb.NavigationCategory)) As Telerik.Web.Mvc.UI.MenuBuilder': Nested sub does not have a signature that is compatible with delegate 'System.Action(Of Telerik.Web.Mvc.UI.MenuItem, AIMSWeb.NavigationCategory)'.
    'Public Function BindTo(viewDataKey As String, siteMapAction As System.Action(Of Telerik.Web.Mvc.UI.MenuItem, Telerik.Web.Mvc.SiteMapNode)) As Telerik.Web.Mvc.UI.MenuBuilder': Nested sub does not have a signature that is compatible with delegate 'System.Action(Of Telerik.Web.Mvc.UI.MenuItem, Telerik.Web.Mvc.SiteMapNode)'. D:\Projects\Advance\AIMSWeb\AIMSWeb\Views\Shared\Navigation.ascx 3 5 AIMSWeb

3 Answers, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 01 Jun 2010, 08:09 AM
Hi John,

Here is a working sample - the menu is bound to the controls collection of the master page:

<%: Html.Telerik().Menu() _
        .Name("Menu") _
        .BindTo(Controls.Cast(Of Control)(),
                Sub(mappings)
                    mappings.For(Of Control)(
                        Sub(binding)
                            binding.ItemDataBound(
                                Sub(item, ctrl)
                                    item.Text = ctrl.ClientID
                                End Sub)
                            binding.Children(
                                Function(ctrl)
                                    Return ctrl.Controls
                                End Function)
                        End Sub)
                End Sub)
 
 %>


I hope this helps,
Atanas Korchev
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.
0
John
Top achievements
Rank 2
answered on 01 Jun 2010, 09:47 AM
Hi Atanas

Thanks for the response, defintely new to these lambas and this one stumped me.  I have reworked your code and are posting the resulting code I used so hope it helps soemone else.

John

<%: Html.Telerik().Menu() _  
            .Name("Menu") _  
            .BindTo(Model,  
                    Sub(mappings)  
                        mappings.For(Of NavigationCategory)(  
                            Sub(binding)  
                                binding _  
                                    .ItemDataBound(  
                                        Sub(item, ctrl)  
                                            item.Text = ctrl.Name  
                                            If Not String.IsNullOrWhiteSpace(ctrl.Url) Then 
                                                item.Url = ctrl.Url  
                                            End If 
                                        End Sub) _  
                                    .Children(  
                                        Function(ctrl)  
                                            Return ctrl.NavigationItems  
                                        End Function)  
                            End Sub)  
                        mappings.For(Of NavigationItem)(  
                            Sub(binding)  
                                binding.ItemDataBound(  
                                    Sub(item, ctrl)  
                                        item.Text = ctrl.Name  
                                        If Not String.IsNullOrWhiteSpace(ctrl.Url) Then 
                                            item.Url = ctrl.Url  
                                        End If 
                                    End Sub)  
                            End Sub)  
                    End Sub)%> 


0
Nathan
Top achievements
Rank 1
answered on 10 Nov 2011, 08:52 PM
This solution is nice if you are using .Net 4, but what if you are using .Net 3.5 and do not have the use of Sub..End Sub in a Lambda expression?
Tags
Menu
Asked by
John
Top achievements
Rank 2
Answers by
Atanas Korchev
Telerik team
John
Top achievements
Rank 2
Nathan
Top achievements
Rank 1
Share this question
or