Binding to two tables.....

2 posts, 0 answers
  1. Everett
    Everett avatar
    4 posts
    Member since:
    Jul 2008

    Posted 30 Dec 2008 Link to this post

    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> 
  2. Atanas Korchev
    Admin
    Atanas Korchev avatar
    8462 posts

    Posted 02 Jan 2009 Link to this post

    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.
Back to Top