ExtAspNet创建手风琴菜单没有显示数据库菜单信息,求助
protected void Page_Init(object sender, EventArgs e)
{
LoadData();
}
private ExtAspNet.Accordion LoadData()
{
SqlConnection conn = Sqlhelper.conn;
string selectcmd = "select z_id,z_parentid,z_name from userzutest where z_id<>2";
SqlDataAdapter da = new SqlDataAdapter(selectcmd, conn);
ExtAspNet.Tree Tree1 = new ExtAspNet.Tree();
// 模拟从数据库返回数据表
// DataTable table = CreateDataTable();
conn.Open();
DataSet ds = new DataSet();
da.Fill(ds);
// ds.Tables.Add(table);
ds.Relations.Add("TreeRelation", ds.Tables[0].Columns["z_id"], ds.Tables[0].Columns["z_parentid"], false);
ExtAspNet.Accordion accordion = new ExtAspNet.Accordion();
accordion.ShowBorder = false;
accordion.ShowHeader = false;
foreach (DataRow row in ds.Tables[0].Rows)
{
if (row["z_parentid"].Equals(1))
{
AccordionPane accordionPane = new AccordionPane();
accordion.Panes.Add(accordionPane);
accordionPane.Title = row["z_name"].ToString();
accordionPane.ShowBorder = false;
accordionPane.BodyPadding = "2px 0 0 0";
ExtAspNet.Tree tree = new ExtAspNet.Tree();
accordionPane.Items.Add(tree);
tree.ShowBorder = false;
tree.ShowHeader = false;
tree.AutoScroll = true;
tree.EnableArrows = true;
ResolveSubTree(row,tree.Nodes);
}
}
conn.Close();
return accordion;
}
/*******************************************************************************************************/
private void ResolveSubTree(DataRow dataRow, ExtAspNet.TreeNodeCollection nodes)
{
DataRow[] rows = dataRow.GetChildRows("TreeRelation");
if (rows.Length > 0)
{
foreach (DataRow row in rows)
{
ExtAspNet.TreeNode node = new ExtAspNet.TreeNode();
node.Expanded = true;
nodes.Add(node);
node.Text = row["z_name"].ToString();
node.NavigateUrl = "http://www.baidu.com";
ResolveSubTree(row, node.Nodes);
}
}
}
|