问题如题
多谢指教

解决方案 »

  1.   

    有复选框,所以会有选中问题
    最好是用js遍历,或者用ajax也可以
    但是要无刷新
      

  2.   

    function CheckOn(obj)
    {
        var div1 = WebForm_GetParentByTagName(obj,'DIV');
        if(div1 != null)
        {
            var checkBoxs = div1.getElementsByTagName('INPUT'); 
            var parentCheckBoxID = div1.id.replace('Nodes','CheckBox');
            
            var parentCheckBox = document.getElementById(parentCheckBoxID);
            
            var i = 0;
            var count = 0;
            for(i=0;i<checkBoxs.length;i++) 
            {
                if(checkBoxs[i].type=='checkbox')
                {
                    if(checkBoxs[i].checked==false)
                    {           
                        count++;
                        //break;
                    }
                }
                else
                {
                    alert("The node is not a checkbox!");
                    return;
                }
            }
            if(parentCheckBox!=null)
            {
                if(count == checkBoxs.length)
                {
                    parentCheckBox.checked = false;
                    parentCheckBox.disabled= false;
                    
                    CheckOn(parentCheckBox);
                }
                else if(count > 0)
                {
                    parentCheckBox.checked = true;
                    parentCheckBox.disabled = true;
                    
                    CheckOn(parentCheckBox);
                }
                else
                {
                    parentCheckBox.checked = true;
                    parentCheckBox.disabled= false;
                    
                    CheckOn(parentCheckBox);
                } 
            }     
        }
    }function OnTreeNodeChecked() 

        var ele = event.srcElement;
        if(ele.type=='checkbox') 
        { 
            var childrenDivID = ele.id.replace('CheckBox','Nodes');
            var div = document.getElementById(childrenDivID);         if(div != null)
            {
                var checkBoxs = div.getElementsByTagName('INPUT'); 
                for(var i=0;i<checkBoxs.length;i++) 
                { 
                    if(checkBoxs[i].type=='checkbox') 
                    checkBoxs[i].checked=ele.checked; 
                }
            }
            CheckOn(ele);
       }
       
    }<asp:TreeView ID="tv" runat="server" ShowCheckBoxes="All"  ShowLines="True">
    tv.Attributes.Add("OnClick", "OnTreeNodeChecked()");
      

  3.   

        private void AddDirectories(TreeNode node)
            {
                //node.Expand();
                node.Nodes.Clear();
                listView1.Items.Clear();
                string strPath = node.FullPath; 
                try
                {
                    strPath = strPath.Remove(0, 5);
                    finalpath = strPath + "\\";
                }
                catch
                {
                    if (strPath == "我的电脑")
                    {
                        Get_Drivers();
                        finalpath = "";
                        toolStripTextBox1.Text = strPath;
                        return;
                    }
                    strPath = strPath.Remove(0, 4);
                }
                DirectoryInfo dirinfo;
                DirectoryInfo[] dirinfos;
                FileInfo[] files;
                try
                {
                    dirinfo = new DirectoryInfo(strPath);//获得当前目录
                    dirinfos = dirinfo.GetDirectories();//返回当前目录子目录
                    files = dirinfo.GetFiles();
                }
                catch
                {
                    try
                    {
                        strPath = Environment.GetFolderPath(Environment.SpecialFolder.Personal) + "\\" + strPath;
                        dirinfo = new DirectoryInfo(strPath);
                        dirinfos = dirinfo.GetDirectories();
                        files = dirinfo.GetFiles();
                        finalpath = strPath +"\\";
                    }
                    catch
                    {
                        return;
                    }
                }
                foreach (DirectoryInfo dir in dirinfos)
                {
                    TreeNode tnDir = new TreeNode(dir.Name, 2, 3);
                    node.Nodes.Add(tnDir);
                    ListViewItem listTd = new ListViewItem(dir.Name, 2);
                    listView1.Items.Add(listTd);
                }
                foreach (FileInfo file in files)
                {
                    ListViewItem listTd = new ListViewItem(file.Name, 3);
                    listView1.Items.Add(listTd);
                }
                toolStripTextBox1.Text = finalpath.Remove(finalpath.Length-1,1);
            }选中值是这个吧
      listview.selectitems[0].text
      

  4.   

    我要的是遍历Treeview获取复选框被选中节点的 value值对楼上写的不是很明白
      

  5.   

    结点的选中属性里调JAVASCRIPT方法,javaScript里写ajax机制