<%@ Page Language="C#" CodeFile="DefaultCS.aspx.cs" Inherits="Menu.Examples.Programming.WebService.DefaultCS" %>
<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml'>
<head runat="server">
<title>Telerik ASP.NET Example</title>
</head>
<body>
<form id="form1" runat="server">
<telerik:RadScriptManager runat="server" ID="RadScriptManager1" />
<telerik:RadSkinManager ID="RadSkinManager1" runat="server" ShowChooser="true" />
<div class="demo-container size-wide">
<h2>Web Service</h2>
<telerik:RadMenu RenderMode="Lightweight" ID="RadMenu1" runat="server" EnableRoundedCorners="true" EnableShadows="true" Style="z-index: 10">
<WebServiceSettings Path="ProductCategories.asmx" Method="GetMenuCategories" />
<LoadingStatusTemplate>
<asp:Image runat="server" ID="LoadingImage" ImageUrl="Images/loading.gif" ToolTip="Loading..."
Width="16px" Height="16px" Style="margin-top: 8px"></asp:Image>
</LoadingStatusTemplate>
<Items>
<telerik:RadMenuItem Text="Products" Value="1" ExpandMode="WebService" />
<telerik:RadMenuItem Text="Purchase" Value="132" ExpandMode="WebService" />
<telerik:RadMenuItem Text="Support" Value="141" ExpandMode="WebService" />
<telerik:RadMenuItem Text="Community" Value="155" ExpandMode="WebService" />
<telerik:RadMenuItem Text="Corporate" Value="164" ExpandMode="WebService" />
</Items>
</telerik:RadMenu>
</div>
<div class="demo-container size-wide">
<h2>WCF Web Service</h2>
<telerik:RadMenu RenderMode="Lightweight" runat="server" ID="RadMenu2" DataSourceID="EntityDataSource2" DataTextField="Title" Style="z-index: 9"
DataValueField="CategoryId" EnableRoundedCorners="true" EnableShadows="true">
<WebServiceSettings Path="MenuWcfService.svc" Method="LoadData" />
<DataBindings>
<telerik:RadMenuItemBinding Depth="0" ExpandMode="WebService" />
</DataBindings>
</telerik:RadMenu>
<asp:EntityDataSource runat="server" ID="EntityDataSource2" ConnectionString="name=TelerikReadOnlyEntities"
DefaultContainerName="TelerikReadOnlyEntities" EntitySetName="ProductCategories" Where="it.[parentId] IS NULL">
</asp:EntityDataSource>
</div>
<div class="demo-container size-wide">
<h2>ADO.NET Service</h2>
<telerik:RadMenu RenderMode="Lightweight" runat="server" ID="RadMenu3" DataSourceID="EntityDataSource1" DataTextField="Text" Style="z-index: 8"
DataValueField="id" OnClientItemPopulating="itemPopulating" EnableRoundedCorners="true"
EnableShadows="true">
<DataBindings>
<telerik:RadMenuItemBinding Depth="0" ExpandMode="WebService" />
</DataBindings>
</telerik:RadMenu>
<telerik:RadScriptBlock ID="RadScriptBlock1" runat="server">
<script type="text/javascript">
//<![CDATA[
function onSuccess(result, item) {
//the result in JSON format is available as a "d" field
var data = result.d;
//Traverse the array of objects and create menu items
for (var i = 0; i < data.length; i++) {
var dataItem = data[i];
var childitem = new Telerik.Web.UI.RadMenuItem();
childitem.set_text(dataItem.Text);
childitem.set_value(dataItem.id);
item.get_items().add(childitem);
}
item.set_expandMode(Telerik.Web.UI.MenuItemExpandMode.ClientSide);
item.open();
}
function itemPopulating(sender, args) {
var item = args.get_item();
//filter only the child items of the current item
var filter = "&$filter=parentId eq " + item.get_value();
//Call the ADO.NET Data Service
$telerik.$.ajax({
type: "GET", // HTTP method
url: '<%= ResolveUrl("menuadonetservice.svc/Links?") %>' + filter, // ADO.NET DataService URL
contentType: "application/json; charset=utf-8", //request the result to be in JSON
dataType: "json",
success: function(result) { //callback method to invoke when the request is complete
onSuccess(result, item);
}
});
args.set_cancel(true);
}
//]]>
</script>
</telerik:RadScriptBlock>
<asp:EntityDataSource runat="server" ID="EntityDataSource1" ConnectionString="name=TelerikReadWriteEntities"
DefaultContainerName="TelerikReadWriteEntities" EntitySetName="Links" Where="it.[parentId] IS NULL">
</asp:EntityDataSource>
</div>
<div class="demo-container size-wide">
<h2>OData Binding</h2>
<telerik:RadMenu RenderMode="Lightweight" runat="server" ID="RadMenu4" ODataDataSourceID="RadODataDataSource1" Style="z-index: 7"
PersistLoadOnDemandItems="false">
<DataBindings>
<telerik:RadMenuItemBinding ModelID="Category" TextField="CategoryName" ValueField="CategoryID"
Depth="0" FieldID="CategoryID" />
<telerik:RadMenuItemBinding ModelID="Product" TextField="ProductName" ValueField="ProductID"
Depth="1" FieldParentID="CategoryID" />
</DataBindings>
</telerik:RadMenu>
<telerik:RadODataDataSource runat="server" ID="RadODataDataSource1">
<Schema>
<telerik:DataModel ModelID="Category" Set="Categories">
<telerik:DataModelField FieldName="CategoryID" />
<telerik:DataModelField FieldName="CategoryName" />
</telerik:DataModel>
<telerik:DataModel ModelID="Product" Set="Products">
<telerik:DataModelField FieldName="ProductName" />
<telerik:DataModelField FieldName="ProductID" />
<telerik:DataModelField FieldName="CategoryID" />
</telerik:DataModel>
</Schema>
</telerik:RadODataDataSource>
</div>
</form>
</body>
</html>