先设计一个窗体 左边拖一个treeview控件 右边拖一个datagird控件
数据库已帮定好了,而且treeview的节点也能显示数据库里的内容了
现在我想点击左边的treeview节点后如何在右边的datagird里显示对应的
treeview里的数据内容呢? 请朋友附上详细代码!!!!谢谢!

解决方案 »

  1.   

    如何用它实现与sql2000数据库的递归算法请强人指点一下谢谢
      

  2.   

    DataRow dataRow=(DataRow)treeNode.Tag;
    =======================================  数据不是在TAG里吗 ~
      

  3.   

    http://community.csdn.net/Expert/topic/3877/3877541.xml?temp=.1423914
      

  4.   

    #region Tree Selected
    /// <summary>
    /// Tree Selection Change
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void tvDocDir_SelectedIndexChange(object sender, Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs e)
    {
    this.SetPageView(MainPageStatus.ViewStatusInit); try
    {
    TreeNode node = TreeOperationDB.GetNodeId(this.tvDocDir); int right = this.GetCurrentNodeRight(node.ID);
    if( right < 1 )
    {
    // Users dont have read permission
    return;
    }
    else if( right  < 2 )
    {
    // Only Read
    this.dgDocDetail.Columns[5].Visible = false;
    this.btnAddDoc.Visible = false;
    }
    else if( right  < 3 )
    {
    // Update
    this.dgDocDetail.Columns[5].Visible = false;
    this.btnAddDoc.Visible = true;
    }
    else
    {
    this.dgDocDetail.Columns[5].Visible = true;
    this.btnAddDoc.Visible = true;
    } this.Session["DocumentList"] = null;
    DataTable dtDocDetail = this.GetDocumentList(); if( dtDocDetail.Rows.Count == 0 )
    {
    this.DivDocDetail.Visible = false;
    }
    else
    {
    this.DivDocDetail.Visible = true;
    dgDocDetail.DataSource = dtDocDetail;
    dgDocDetail.DataBind();
    } this.SetPageView(MainPageStatus.ViewStatusFileList);
    }
    catch( ApplicationException ex )
    {
    if( ex.Message == "1060")
    {
    this.NodeLostManagement( ex.Message );
    }
    else if( ex.Message == "1062" )
    {
    // TreeNode Has been Modifiey
    this.ShowMessage(this.GetMessage(ex.Message)); // Rebuild Tree
    string treePath = this.tvDocDir.SelectedNodeIndex;
    this.rebuildTree(treePath); this.tvDocDir_SelectedIndexChange( new object() , new Microsoft.Web.UI.WebControls.TreeViewSelectEventArgs("0","0") );
    }
    }
    catch( Exception ex )
    {
    this.Response.Redirect("Error.aspx?errorMsg="+Server.UrlEncode(ex.Message));
    }
    } /// <summary>
    /// Reload Document List
    /// </summary>
    private DataTable GetDocumentList()
    {
    if( this.Session["DocumentList"] != null )
    {
    return (DataTable)this.Session["DocumentList"];
    }
    else
    {
    TreeNode node = TreeOperationDB.GetNodeId(this.tvDocDir); // Get Document of current node
    DataTable dtDocDetail = new DmsMainDB().DocList( node , this.UserInfo.LangCode );
    this.Session["DocumentList"] = dtDocDetail;
    return dtDocDetail;
    }
    }
      

  5.   

    /// <summary>
    /// Get Selected Tree Node ID
    /// </summary>
    /// <param name="indexList">Select Index</param>
    /// <returns></returns>
    public static TreeNode GetNodeId( TreeView docTree )
    {
    // Split the selected value
    string[] strId = docTree.SelectedNodeIndex.Split('.'); TreeNode treeNodeRet = new TreeNode(); // First Selected Node Index
    int intId = int.Parse(strId[0]); // First Selected Node
    treeNodeRet = docTree.Nodes[intId]; for(int i=1;i< strId.Length;i++)
    {
    intId = int.Parse(strId[i]); // Move to next node in the treeview
    treeNodeRet = treeNodeRet.Nodes[intId];
    } return treeNodeRet;
    }
      

  6.   

    例如我需要显示一个公司的组织结构图
    这样来显示:
    +人事部 (点击显示领导)
       - 组1(点击显示领导1,员工1)
       - 组2(点击显示领导2,员工2)
    +信息部 (点击显示领导)
       - 组1(点击显示领导1,员工1)
       - 组2(点击显示领导2,员工2)现在有数据表 username,dept(部门),group(组),place(职位)
    我需要从数据表动态显示这样的结构,请问如何来实现
    请提供具体的实例(c#+sql2000) 最好有份源码,这样学习起来会更容易理解(分不够我可以加) 
    万分感谢!!!![email protected]