前台只需要放一個 treeview控件就行
後台
protected void Page_Load(object sender
{
if (!IsPostBack)
bindTree();
}
private void bindTree()
{
DataTable dt = this
this
}
private void FillNode(DataTable dt
{
DataView dv = new DataView(dt);
if (node == null) //根結點
{
dv
}
else //不是根結點
{
dv
}
foreach (DataRowView drv in dv) //遍歷填充節點的所有子節點
{
TreeNode no = new TreeNode(drv["menuname"]
FillNode(dt
if (node == null)
{
this
}
else
{
node
}
}
}
private DataTable GetTreeData()
{
string strcnn = ConfigurationManager
using (SqlConnection sqlcnn = new SqlConnection(strcnn))
{
SqlCommand sqlcmm = sqlcnn
sqlcmm
SqlDataAdapter da = new SqlDataAdapter(sqlcmm);
DataSet ds = new DataSet();
da
return ds
}
}
From:http://tw.wingwit.com/Article/program/net/201311/14260.html