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> |