要怎么做,下面是treeview绑定的代码(数据层用dataset数据集生成的)
1 protected void Page_Load(object sender, EventArgs e) 2 { 3 if (!Page.IsPostBack) 4 PopulateTreeView(); 5 } 6 private void PopulateTreeView() 7 { 8 clindexTableAdapter clindexAdapter = new clindexTableAdapter(); 9 DataTable treeViewData = clindexAdapter.getclindex(); 10 AddTopTreeViewNodes(treeViewData); //绑定父节点 11 } 12 private void AddTopTreeViewNodes(DataTable treeViewData) 13 { 14 DataView view = new DataView(treeViewData); 15 view.RowFilter = "ParentID = 0"; 16 foreach (DataRowView row in view) 17 { 18 TreeNode newNode = new TreeNode(row["SortName"].ToString(), row["OrderId"].ToString()); 19 tvindex.Nodes.Add(newNode); 20 AddChildTreeViewNodes(treeViewData, newNode);//绑定子节点 21 } 22 23 } 24 private void AddChildTreeViewNodes(DataTable treeViewData, TreeNode parentTreeViewNode) 25 { 26 DataView view = new DataView(treeViewData); 27 view.RowFilter = "ParentID=" + parentTreeViewNode.Value; 28 foreach (DataRowView row in view) 29 { 30 TreeNode newNode = new TreeNode(row["SortName"].ToString(), row["OrderId"].ToString()); 31 parentTreeViewNode.ChildNodes.Add(newNode); 32 AddChildTreeViewNodes(treeViewData, newNode);//递归,绑定子节点 33 } 34 }
//在treeview的TreeNodeExpanded指当前节点展开时发生
protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
//获取当前选中节点的Name
string nodeName=TreeView1.SelectedNode.Text;
StringBuilder sql = new StringBuilder();
sql.Append(string.Format("SELECT * FROM UserInfo WHERE Name={0}",nodeName));
}
第一種,把 treeview 放到模板頁。
第二種,把treeview放到iframe中。