Hi guys,
According to this help:
http://www.telerik.com/help/aspnet-ajax/menu-populate-from-wcf-service.html
I can successfully run OnClientItemPopulatingHandler and there is debug breakpoint that show me GetData is run and the items.count is 4. After that,there is no any radmenu drop-down as expected. Here is the code:
Mark-up
<head runat="server">
<title></title>
<script type="text/javascript">
function OnClientItemPopulatingHandler(sender, e) {
var context = e.get_context();
//using jQuery to get the checked item and pass it to the server
context["ProductSuite"] = $telerik.$("input[name='rblSuites']:checked").val();
}
function OnClientItemPopulatedHandler(sender, e) {
var items = e.get_item().get_items();
for (var i = 0; i < items.get_count(); i++) {
var item = items.getItem(i);
//getting the attribute of the item
var myCustomAttribute = item.get_attributes().getAttribute("MyCustomAttribute");
//do something with the attribute
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<asp:RadioButtonList ID="rblSuites" runat="server">
<asp:ListItem Selected="True">ASP.NET AJAX</asp:ListItem>
<asp:ListItem>WPF</asp:ListItem>
<asp:ListItem>Silverlight</asp:ListItem>
<asp:ListItem>Winforms</asp:ListItem>
</asp:RadioButtonList>
<telerik:RadMenu ID="RadMenu1"
OnClientItemPopulating="OnClientItemPopulatingHandler"
OnClientItemPopulated="OnClientItemPopulatedHandler"
runat="server">
<Items>
<telerik:RadMenuItem Text="Products" ExpandMode="WebService">
</telerik:RadMenuItem>
</Items>
<WebServiceSettings Method="GetData" Path="../Services/WcfTopMenu.svc" />
</telerik:RadMenu>
</div>
</form>
</body>
</html>
.SVC
svc code behind
Imports System.ServiceModel
Imports System.ServiceModel.Activation
Imports System.ServiceModel.Web
Imports Telerik.Web.UI
<ServiceContract([Namespace]:="")> _
<AspNetCompatibilityRequirements(RequirementsMode:=AspNetCompatibilityRequirementsMode.Allowed)> _
Public Class WcfTopMenu
<OperationContract()> _
Public Function GetData(ByVal item As RadMenuItemData, ByVal context As IDictionary(Of String, Object)) As RadMenuItemData()
Dim items As New List(Of RadMenuItemData)()
'use the context to get the selected radio button
Dim productsSuite As String = context("ProductSuite").ToString()
'the datasource
'Dim radControls() As String = New String() {"RadMenu", "RadMenu", "RadTreeView", "RadToolBar"}
Dim radControls As List(Of [String]) = New List(Of String)() From { _
"RadMenu", _
"RadMenu", _
"RadTreeView", _
"RadToolBar" _
}
For Each radControl As String In radControls
'Optional: set the attribute of the item which will be used
'in the OnClientNodePopulated event
Dim newItem As New RadMenuItemData() With { _
.Text = String.Format("{0} for {1}", radControl, productsSuite), _
.Value = radControl, _
.ImageUrl = "Images/" + radControl + ".gif", _
.Attributes = New Dictionary(Of String, Object)() From {{"MyCustomAttribute", radControl}}
}
items.Add(newItem)
Next
Return items.ToArray()
End Function
End Class
Did I miss sth? If so, please tell me. Thx!