Chinaunix首页 | 论坛 | 博客
  • 博客访问: 30479438
  • 博文数量: 708
  • 博客积分: 12163
  • 博客等级: 上将
  • 技术积分: 8240
  • 用 户 组: 普通用户
  • 注册时间: 2007-12-04 20:59
文章分类

全部博文(708)

分类: C/C++

2009-01-11 11:27:23



using Microsoft.Web.UI.WebControls;//添加控件的引用

private void GetTreeView()//程序开始
{
 try
 {
  string strSql = "SELECT DISTINCT Menu_id,Menu_name from docmodulemanager where Menu_level = 1 and sn in
  ("+All.Substring(0,All.Length-1).ToString()+")";
  OracleDataAdapter
  objAdapter = new OracleDataAdapter(strSql,objConn);
  DataSet ds = new DataSet();
  ds.Clear ();
  objAdapter.Fill(ds,"temp");
  DataTable dt = ds.Tables["temp"];
  TreeView1.Nodes.Clear();
  //建立根节点,遍历。
  foreach(DataRow dr in dt.Rows)
  {
    TreeNode Root = new TreeNode();
    Root.Text = dr["Menu_name"].ToString();
    TreeView1.Nodes.Add(Root);//建立根节点
    string str = "SELECT Menu_name,menu_addr,sn from docmodulemanager where upper_id = '" + dr["Menu_id"].ToString() + "' and sn in ("+menu_sn.Substring(0,menu_sn.Length-1).ToString()+")"+"order by menu_id,child_id";

    OracleDataAdapter objAdapterNode = new
    OracleDataAdapter(str,objConn);
    DataSet dsNode = new DataSet();
    dsNode.Clear ();
    objAdapterNode.Fill(dsNode,"tempNode");
    DataTable dtNode = dsNode.Tables["tempNode"];
     //建立子节点,遍历。
    foreach(DataRow drNode in dtNode.Rows)
    {
     TreeNode Node = new TreeNode();
     Node.Text = drNode["Menu_name"].ToString();
     Node.Target = ā8ǐ8?"mainbottom";
     string Path = drNode["menu_addr"].ToString();
     int menusn = Convert.ToInt32(drNode["sn"].ToString());
     Node.NavigateUrl = "Transfer.aspx"+"?menu_addr="+ Path;
     Root.Nodes.Add(Node);//建立子节点
    }
   }
  }
  catch
  {
    Response.Write(" <SCRIPT>alert('您没有可操作的菜单项,请与管理员联系!');</SCRIPT> ");
  }
  finally
  {
    if (objConn.State.ToString().Equals ("Open")) objConn.Close();
  }
 }

 

自己写的3级树:

sql:

select a.id ppid,a.mingcheng ppming,b.id cxid,b.mingcheng cxming,c.id xhid,c.xinghao xhming from GZ_qiche_pinpai a,GZ_chexi b,GZ_qiche_shuxing c where a.id=b.pinpaiid and b.id=c.chexi order by ppid,cxid,xhid

 

 

 

//根节点 - 汽车品牌

foreach (DataRow dr in dt.Rows)
{
    TreeNode root;
    string ppming = dr["ppming"].ToString();
    string ppid = dr["ppid"].ToString();
    string cxid = dr["cxid"].ToString();
    string cxming = dr["cxming"].ToString();
    string xhid = dr["xhid"].ToString();
    string xhming = dr["xhming"].ToString();

    bool hadRoot = false;

    foreach (TreeNode tn in carTree.Nodes)
    {
        if (tn.Value == ppid)
        {
            hadRoot = true;

            //一级子节点 - 车系

            TreeNode notec;
            bool hadRootc = false;

            foreach (TreeNode tnc in tn.ChildNodes)
            {
if (tnc.Value == cxid)
{
    hadRootc = true;

    //二级子节点 - 汽车型号

    TreeNode notecc = new TreeNode();
    notecc.Text = xhming;
    notecc.NavigateUrl = "javascript:void(0)";
    notecc.Value = xhming;
    tnc.ChildNodes.Add(notecc);

}

            }

            if (!hadRootc)
            {
notec = new TreeNode();
notec.Text = cxming;
notec.NavigateUrl = "javascript:void(0)";
notec.Value = cxid;
TreeNode notecc = new TreeNode();
notecc.Text = xhming;
notecc.NavigateUrl = "javascript:void(0)";
notecc.Value = xhid;
notec.ChildNodes.Add(notecc);
tn.ChildNodes.Add(notec);
            }

        }

    }

    if (!hadRoot)
    {
        root = new TreeNode();
        root.Text = ppming;
        root.NavigateUrl = "javascript:void(0)";
        root.Value = ppid;
        TreeNode notec = new TreeNode();
        notec.Text = cxming;
        notec.NavigateUrl = "javascript:void(0)";
        notec.Value = cxid;
        TreeNode notecc = new TreeNode();
        notecc.Text = xhming;
        notecc.NavigateUrl = "javascript:void(0)";
        notecc.Value = xhid;
        notec.ChildNodes.Add(notecc);
        root.ChildNodes.Add(notec);
        carTree.Nodes.Add(root);
    }

}

阅读(2255) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~