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

[Solved] Menu's config from xml file

1 Answer 139 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Olo
Top achievements
Rank 1
Olo asked on 17 Jun 2009, 10:45 AM
Hi,
I want to move my html code:
<telerik:RadMenu ID="RadMenu1" runat="server" DataNavigateUrlField="Url"   
            DataSourceID="XmlDataSourceForMenu" DataTextField="Text" DataValueField="Value">  
</telerik:RadMenu> 
      
<asp:XmlDataSource ID="XmlDataSourceForMenu" runat="server"   
        DataFile="~/MenuConfig.xml" XPath="/Items/Item"></asp:XmlDataSource> 
to c# code.
So I wrote in Page_Load:
XmlDataSource XmlDataSourceForMenu = new XmlDataSource();  
XmlDataSourceForMenu.ID = "XmlDataSourceForMenuID";  
XmlDataSourceForMenu.DataFile = "~/MenuConfig.xml";  
XmlDataSourceForMenu.XPath = "/Items/Item";  
 
 
RadMenu1.DataSourceID = XmlDataSourceForMenu.ID;  
RadMenu1.DataNavigateUrlField = "Url";  
RadMenu1.DataTextField = "Text";  
RadMenu1.DataValueField = "Value"
but I get an error
"The DataSourceID of 'RadMenu1' must be the ID of a control of type IDataSource.  A control with ID 'XmlDataSourceForMenuID' could not be found. ".
How can I fix this bug?

1 Answer, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 17 Jun 2009, 12:47 PM
Hello,

You have to add the XmlDataSource to the control collection of the page as shown below inorder to avoid the error:
c#:
        XmlDataSource XmlDataSourceForMenu = new XmlDataSource(); 
        XmlDataSourceForMenu.ID = "XmlDataSourceForMenuID"
        XmlDataSourceForMenu.DataFile = "~/App_Data/XMLFile.xml"
        XmlDataSourceForMenu.XPath = "/Items/Item"
        this.Page.Controls.Add(XmlDataSourceForMenu); 

Thanks
Princy.
Tags
Menu
Asked by
Olo
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or