I'm using Telerik RadControls Q1 2008. I have a Rad Menu on the masterpage of my application and i'm trying to bind it to a linq datacontext.
The binding works fine but my problem is That Child Items are always displayed as root items.
I have checked that ParentId of all roots items is NULL and of all the child items is that of the assigned parent.
Below is the code :
Private Sub LoadMenuItems()
Dim MenuDC As New MenuItemDataContext
RadMenu1.DataSource = MenuDC.usp_TABLE_MENU_ITEM_Select().ToList()
RadMenu1.DataBind()
End Sub
<
telerik:RadMenu
ID
=
"RadMenu1"
runat
=
"server"
Skin
=
"Office2007"
DataFieldID
=
"MENU_ITEM_ID"
DataFieldParentID
=
"PARENT_ID"
DataNavigateUrlField
=
"PAGE_URL"
DataTextField
=
"MENU_ITEM_NAME"
DataValueField
=
"MENU_ITEM_ID"
>
<
DefaultGroupSettings
ExpandDirection
=
"Down"
/>
<
CollapseAnimation
Type
=
"OutQuint"
Duration
=
"200"
></
CollapseAnimation
>
</
telerik:RadMenu
>
I do not know what i'm missing here.
9 Answers, 1 is accepted
i haven't gotten anywhere with the issue. i'm its something trivial, but i just don't know what it is..
From reading other posts in this forum i know people have had issues with Root Items .. but i couldn't find any issues similar to mine.
I guess i have no choice but to wait for telerik to answer.
Any help would be appreciated.
Thanks
Amit
In the meanwhile I've tried to dynamically build the rad menu from the result list of Linq DataContext, which also did not work.
An Interesting thing that i did found was RadMenuItem does not have a property to Set its parent ID.
(E.g. radMenuItem.parentID = 2)
If anyone from telerik reads this post. It will be good to have a property for the same.
Thanks
Amit
Note: I'm gonna revert back to using asp.net Menu and see if that works.
The provided information is not enough for us, we need more details in order to help you. Can you please send us the result list so we can test it? Thanks
Greetings,
Yana
the Telerik team
Thanks for your reply,
Below is the sql table that i've used for Menu
MENU_ITEM_ID PARENT_ID PAGE_URL MENU_ITEM_NAME
3 | NULL | /MenuItemE.aspx | DashBoard |
4 | NULL | /ItemDetails.aspx | Inventory |
5 | 4 | /ItemDetails.aspx | Item Details |
The problem that i'm facing is that all the Menu Items Are bounded as root items and not in the hierarchical manner as they should.
Please let me know if you want any more info .. or should i submit a support ticket.
I have refined my code and finally got it to work (YAY!) to build the Menu dynamically. Below is the Approach I used.
Private
Sub
LoadMenuItems()
Dim
MenuDC
As
New
MenuItemDataContext
Dim
itemL
As
New
List(Of usp_TABLE_MENU_ITEM_SelectResult)
Dim
childL
As
New
List(Of usp_TABLE_MENU_ITEM_SelectResult)
For
Each
item
As
usp_TABLE_MENU_ITEM_SelectResult
In
MenuDC.usp_TABLE_MENU_ITEM_Select
If
item.PARENT_ID IsNot
Nothing
And
item.PARENT_ID <> 0
Then
childL.Add(item)
Else
itemL.Add(item)
End
If
Next
For
i
As
Integer
= 0
To
itemL.Count - 1
Dim
rootM
As
New
RadMenuItem
rootM.Value =
CType
(itemL(i).MENU_ITEM_ID,
String
)
rootM.NavigateUrl = itemL(i).PAGE_URL
rootM.Text = itemL(i).MENU_ITEM_NAME
For
j
As
Integer
= 0
To
childL.Count - 1
If
childL(j).PARENT_ID = itemL(i).MENU_ITEM_ID
Then
Dim
childM
As
New
RadMenuItem
childM.Value =
CType
(childL(j).MENU_ITEM_ID,
String
)
childM.NavigateUrl = childL(j).PAGE_URL
childM.Text = childL(j).MENU_ITEM_NAME
rootM.Items.Add(childM)
End
If
Next
RadMenu1.Items.Add(rootM)
Next
'RadMenu1.DataFieldID = "MENU_ITEM_ID"
'RadMenu1.DataFieldParentID = "PARENT_ID"
'RadMenu1.DataNavigateUrlField = "PAGE_URL"
'RadMenu1.DataTextField = "MENU_ITEM_NAME"
'RadMenu1.DataSource = MenuDC.usp_TABLE_MENU_ITEM_Select().ToList()
'RadMenu1.DataBind()
End
Sub
But I would still like to know why direct binding to datasource (the commented out code) did not work properly.
Also, as i suggested in my earlier post, a property to set the parentId of a radMenuItem will be greatly appreciated.
Amit
I created a simple page to test the provided data and the menu works as expected. Please download the attachment and give it a try.
Regarding the ParentID property - thank you for sending your suggestion, I've logged it and it will be considered.
All the best,
Yana
the Telerik team
Thanks for your response, the page you provided worked fine but when i changed the data source from table to LinqDatacontext, the same issue happened once again, i dont know if this a data issue or something else. I cannot spend more time trying to solve this issue. so for now i'm gonna stick to my approach of binding the menu items dynamically (as shown in my previous post).
Thanks once again.
Amit
I need help!!
Thanks
HANK
XML files
<?xml version="1.0" encoding="utf-8"?>
<Orders>
<Order>
<Id>4c5189d7-2d39-41dc-a0cb-e5136a908543</Id>
<Title>sssssss</Title>
<Description>This is the e-Briefing Book.</Description>
<Url></Url>
<Position>1</Position>
<ParentId></ParentId>
</Order>
<Order>
<Id>39f25e84-74b4-47f9-b348-3b8beabc7a35</Id>
<Title>sssssdddd</Title>
<Description></Description>
<Url></Url>
<Position>1</Position>
<ParentId>4c5189d7-2d39-41dc-a0cb-e5136a908543</ParentId>
</Order>
</Orders>
XSL
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Orders">
<Orders>
<xsl:apply-templates />
</Orders>
</xsl:template>
<xsl:template match="Order">
<Order SiteId="{Id}"
Title="{Title}"
Description="{Description}"
Url="{Url}"
Position="{Position}"
ParentId="{ParentId}" />
</xsl:template>
</xsl:stylesheet>
XMLDATASOURCE definition
<
asp:XmlDataSource ID="XDS"
DataFile="Orders.xml"
TransformFile="Orders.xsl"
XPath="Orders/Order"
runat="server"></asp:XmlDataSource>
RadMenu Definition
<telerik:RadMenu runat="server" ID="rmnuGlobalNav"
Skin="NIAMS" EnableEmbeddedSkins="false">
<DefaultGroupSettings RepeatColumns="1" RepeatDirection="Vertical" />
</telerik:RadMenu>
Behind Code
rmnuGlobalNav.DataFieldID =
"Id";
rmnuGlobalNav.DataFieldParentID =
"ParentId";
rmnuGlobalNav.DataTextField =
"Title";
rmnuGlobalNav.DataNavigateUrlField =
"Url";
rmnuGlobalNav.DataSourceID =
"XDS";
rmnuGlobalNav.DataBind();
When using XmlDataSource the items hierarchy is built in the xml file, not using DataFieldID, DataFieldParentID properties. Please check this help article for more details.
Kind regards,
Yana
the Telerik team