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

Binding to two tables.....

1 Answer 60 Views
Menu
This is a migrated thread and some comments may be shown as answers.
Everett
Top achievements
Rank 1
Everett asked on 31 Dec 2008, 04:48 AM

I'm binding an Rad menu to two data tables.   The code below is working but I can't get rid of the root node generated by the code.  Any ideas?, Or is there a better approach?

Return XML ..

public static string GetMenuItemsFromSQL()  
    {  
        string xml = string.Empty;  
        string queryString = @"SELECT Department.Name AS name, Department.DepartmentID AS id,  
                               Department.Description AS desription, Category.Name AS name,   
                               Category.CategoryID AS id  
                              FROM Department AS department INNER JOIN  
                                Category AS category ON department.DepartmentID = category.DepartmentID  
                                ORDER BY department.DepartmentID                      
                                FOR XML Auto, ROOT('departments')";  
 
        string connectionString = WebSiteConfiguration.DbConnectionString;  
 
 
        using (SqlConnection connection = new SqlConnection(connectionString))  
        {  
            SqlCommand SelectCommand = new SqlCommand(queryString, connection);  
            connection.Open();  
            XmlReader xr = SelectCommand.ExecuteXmlReader();  
            xr.MoveToContent();// move to the root node  
            xml = xr.ReadOuterXml();  
        }  
        return xml;  

From .ascx.cs file.  Code behind
protected void Page_Load(object sender, EventArgs e)  
    {  
        XmlDataSource1.Data = CatalogAccess.GetMenuItemsFromSQL();  
          
    }  
    protected void RadMenu1_ItemDataBound(object sender, RadMenuEventArgs e)  
    {  
        if (e.Item.Level > 0)//set tooltip only for child items     
        {  
            XmlElement element = (XmlElement)e.Item.DataItem;  
            e.Item.Text = element.Attributes["name"].Value;  
              
        }     
    } 

From .ascx file.
<telerik:RadMenu ID="RadMenu1" Runat="server"   
    EnableTheming="True" DataSourceID="XmlDataSource1"   
    onitemdatabound="RadMenu1_ItemDataBound"  > 
<CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation> 
</telerik:RadMenu> 
 
 
<asp:XmlDataSource ID="XmlDataSource1" runat="server"></asp:XmlDataSource> 

1 Answer, 1 is accepted

Sort by
0
Atanas Korchev
Telerik team
answered on 02 Jan 2009, 01:43 PM
Hello Everett,

You can use the XPath property of the XmlDataSource to get rid of the root node. Please check our inline example for additional info.

Regards,
Albert
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Menu
Asked by
Everett
Top achievements
Rank 1
Answers by
Atanas Korchev
Telerik team
Share this question
or