I'm trying to bind a RadPanel to Two database tables. I would like the headers to bind to a department table and expand to display a list of categories in that department. I'm close to getting this working, but I'm ending up with one Header (with the xml root node displayed) and expanding to display departments. I think I'm off a level, but can't seem to make it work. I tried xpath = /departments/department but it displays nodes instead of attribute( "department" instead of "department name"). Here's my code. If there's a completely different approach, I'm willing to try it. Thanks in advance for any help.
//From Access class, this works fine with standard treeview.
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();
xml = xr.ReadOuterXml();
}
return xml;
}
//.cs page
protected void Page_Load(object sender, EventArgs e)
{
XmlDataSource1.Data =
CatalogAccess.GetMenuItemsFromSQL();
}
//.ascx
<telerik:RadPanelBar ID="RadPanelBar1" Runat="server" Skin="Web20" ExpandMode="SingleExpandedItem"
DataSourceID="XmlDataSource1" >
<CollapseAnimation Type="None" Duration="100"></CollapseAnimation>
<DataBindings>
<telerik:RadPanelItemBinding DataMember="department" Depth="1" TextField="name" />
<telerik:RadPanelItemBinding DataMember="category" Depth="2" TextField="name" />
</DataBindings>
<
ExpandAnimation Type="None" Duration="10"></ExpandAnimation>
</telerik:RadPanelBar>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" ></asp:XmlDataSource>