I am fairly new to Rad controls. When i try to bind the rad menu to the hierarchial data source it is not displaying in the hierarchial order but instead showed all the items in a single row.
I tried to run the sample code from telerik site. Even with the sample the rad menu shows the items in single row instead of hierarchial manner. Please help me in this...
ASPX Code:
| <%@ Register TagPrefix="telerik" Namespace="Telerik.Web.UI" Assembly="Telerik.Web.UI" %> | |
| <%@ Page Language="c#" CodeFile="Default.aspx.cs" AutoEventWireup="true" | |
| Inherits="Telerik.Web.Examples.Menu.HierarchicalBinding.Default"%> | |
| <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> | |
| <html xmlns="http://www.w3.org/1999/xhtml"> | |
| <head id="Head1" runat="server"> | |
| </head> | |
| <body class="BODY"> | |
| <form id="mainForm" method="post" runat="server"> | |
| <telerik:RadScriptManager ID="RadScriptManager1" runat="server"> | |
| </telerik:RadScriptManager> | |
| <telerik:RadStyleSheetManager ID="RadStyleSheetManager1" runat="server"> | |
| </telerik:RadStyleSheetManager> | |
| <telerik:RadMenu ID="RadMenu1" runat="server" EnableTheming="true"></telerik:RadMenu> | |
| </form> | |
| </body> | |
| </html> |
| using System; | |
| using System.Collections.Generic; | |
| using System.Configuration; | |
| using System.Data; | |
| using System.Data.SqlClient; | |
| using System.Web.UI.WebControls; | |
| using Telerik.Web.UI; | |
| using System.Collections; | |
| namespace Telerik.Web.Examples.Menu.HierarchicalBinding | |
| { | |
| public partial class Default : System.Web.UI.Page | |
| { | |
| internal class SiteDataItem | |
| { | |
| private string _text; | |
| private string _url; | |
| private int _id; | |
| private int? _parentId; | |
| public string Text | |
| { | |
| get { return _text; } | |
| set { _text = value; } | |
| } | |
| public string Url | |
| { | |
| get { return _url; } | |
| set { _url = value; } | |
| } | |
| public int ID | |
| { | |
| get { return _id; } | |
| set { _id = value; } | |
| } | |
| public int? ParentID | |
| { | |
| get { return _parentId; } | |
| set { _parentId = value; } | |
| } | |
| public SiteDataItem(int id, int? parentId, string text, string url) | |
| { | |
| _id = id; | |
| _parentId = parentId; | |
| _text = text; | |
| _url = url; | |
| } | |
| } | |
| private void BindToIEnumerable() | |
| { | |
| List<SiteDataItem> siteData = new List<SiteDataItem>(); | |
| siteData.Add(new SiteDataItem(1, 0, "All Sites", "")); | |
| siteData.Add(new SiteDataItem(2, 1, "Search Engines", "")); | |
| siteData.Add(new SiteDataItem(3, 1, "News Sites", "")); | |
| siteData.Add(new SiteDataItem(4, 2, "Yahoo", "http://www.yahoo.com")); | |
| siteData.Add(new SiteDataItem(5, 2, "MSN", "http://www.msn.com")); | |
| siteData.Add(new SiteDataItem(6, 2, "Google", "http://www.google.com")); | |
| siteData.Add(new SiteDataItem(7, 3, "CNN", "http://www.cnn.com")); | |
| siteData.Add(new SiteDataItem(8, 3, "BBC", "http://www.bbc.co.uk")); | |
| siteData.Add(new SiteDataItem(9, 3, "FOX", "http://www.foxnews.com")); | |
| RadMenu1.DataTextField = "Text"; | |
| RadMenu1.DataNavigateUrlField = "Url"; | |
| RadMenu1.DataFieldID = "ID"; | |
| RadMenu1.DataFieldParentID = "ParentID"; | |
| RadMenu1.DataSource = siteData; | |
| RadMenu1.DataBind(); | |
| } | |
| protected void Page_Load(object sender, EventArgs e) | |
| { | |
| if (!Page.IsPostBack) | |
| { | |
| BindToIEnumerable(); | |
| } | |
| } | |
| } | |
| } | |
| <script type="text/javascript"> |
| function DisplayDetails() |
| { |
| var divDetails = document.getElementById('divDetails'); |
| divDetails.style.display = "inline"; |
| } |
| function CloseActiveToolTip() |
| { |
| setTimeout(function(){ |
| var tooltip = Telerik.Web.UI.RadToolTip.getCurrent(); |
| if (tooltip) tooltip.hide(); |
| }, 1000); |
| } |
| function showToolTip(element,cntid) |
| { |
| var tooltipManager = $find("<%= RadToolTipManager1.ClientID %>"); |
| if (!tooltipManager) return; |
| var tooltip = tooltipManager.getToolTipByElement(element); |
| if (!tooltip) |
| { |
| tooltip = tooltipManager.createToolTip(element); |
| tooltip.set_value(cntid); |
| } |
| element.onmouseover = null; |
| tooltip.show(); |
| } |
| </script> |
| <telerik:RadToolTipManager runat="server" ID="RadToolTipManager1" Position="right" |
| RelativeTo="Element" Width="350px" Height="260px" Animation="Resize" HideEvent="LeaveToolTip" |
| Skin="WebBlue"> |
| <WebServiceSettings Path="~/WebService.asmx" Method="GetCartesPubReg" Runat="Server" /> |
| </telerik:RadToolTipManager> |
| <telerik:ClientTemplate Name="View" runat="server"> |
| <a href="ItemViewUrl" onmouseover="showToolTip(this,'{#ID#}');">{#MetaFields.Title#}</a> |
| </telerik:ClientTemplate> |
OK you may be confused by the title of the post, but I didn't really know how to express a good title for the post.
Here's what I have, I've got a nested grid in a grid and on events such as item_databound of the nested grid I need to find the parent row of the nested grid.
I've found a convoluted way in finding it, but I'm sure there's a simpler way, here's how I do it on the item_databound:
DirectCast(e.Item.Parent.Parent.Parent.Parent.Parent.Parent, Telerik.Web.UI.GridNestedViewItem).ParentItem
I have a similar convoluted way in getting this in a rowdrop event from the nested grid's
DirectCast(e.DragedItems(0).Parent.Parent.Parent.Parent.Parent.Parent, Telerik.Web.UI.GridNestedViewItem).ParentItem
Here's a quick example of what I'm doing:
| Public Sub rdgInvoices_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) 'Handles rdgInvoices.ItemDataBound |
| Static Total As Double |
| If TypeOf e.Item Is Telerik.Web.UI.GridDataItem Then |
| (e.Item.Parent, "TelerikForAjax") |
| Dim gdiParent As Telerik.Web.UI.GridDataItem = DirectCast(e.Item.Parent.Parent.Parent.Parent.Parent.Parent, Telerik.Web.UI.GridNestedViewItem).ParentItem |
| If DirectCast(gdiParent.FindControl("lblDirectExpense"), Label).Text = "1" OrElse DirectCast(e.Item.FindControl("lblDirectExpense"), Label).Text = "1" Then |
| With e.Item |
| DirectCast(.FindControl("lblInvoice"), Label).Visible = False |
| With DirectCast(.FindControl("txtInvoice"), TextBox) |
| .Visible = True |
| ' ''On Error Resume Next |
| ' ''.Attributes.Remove("updateDE") |
| ' ''On Error GoTo 0 |
| ' ''.Attributes.Add("onChange", "updateDE('" & directcast(e.Item.FindControl("txtInvoice"), Label).ClientID & "', '" & & "')") |
| End With |
| Dim rdg As Telerik.Web.UI.GridDataItem = ParentRow(e.Item.Parent, "TelerikForAjax") |
| With DirectCast(.FindControl("txtAmount"), TextBox) |
| .Attributes.Add("onChange", "updateDE('" & DirectCast(e.Item.FindControl("lblAmount"), Label).ClientID & "','" & DirectCast(.FindControl("txtAmount"), TextBox).ClientID & "', '" & DirectCast(rdgCategoryBudget.Items(CurrentCategoryRow).FindControl("txtReconciled"), TextBox).ClientID & "', '" & DirectCast(rdg.FindControl("txtReconciled"), TextBox).ClientID & "', '" & DirectCast(rdgCategoryBudget.Items(CurrentCategoryRow).FindControl("lblSavings"), Label).ClientID & "', '" & DirectCast(rdgCategoryBudget.Items(CurrentCategoryRow).FindControl("lblTotal"), Label).ClientID & "')") |
| .ReadOnly = Not AllowReconciliation |
| End With |
| End With |
| End If |
| End Sub |
| <telerik:RadAjaxLoadingPanel ID="LoadingPanel1" runat="server" Transparency="75" |
| MinDisplayTime="500" BackColor="#E0E0E0"> |
| <img src='<%= RadAjaxLoadingPanel.GetWebResourceUrl(Page, "Telerik.Web.UI.Skins.Default.Ajax.loading6.gif") %>' |
| alt="Loading..." style="border: 0; margin-top: 40px;" /> |
| </telerik:RadAjaxLoadingPanel> |