我想问一下,我在treeview里面选中了某个checkbox,然后向通过单击按钮把选中的值显示出来,应该怎么实现,有哪位知道的麻烦告诉下,谢谢,要后台实现的那种

解决方案 »

  1.   

    遍历checkbox 
    if(this.checkbox.checked==true)
    {}
      

  2.   

    给你做一下:
    protected void Button1_Click(object sender, EventArgs e)
        {        
           ClientScript.RegisterClientScriptBlock(this.GetType(),"","<script>alert('"+getString(this.TreeView1.CheckedNodes)+"')</script>");
        }    string getString(TreeNodeCollection item)
        {
            string a = "";
            foreach (TreeNode var in item)
            {
                if (var.Checked)
                {
                    a= var.Text;
                    break;
                }
                if (var.ChildNodes.Count>0)
                {
                    getString(var.ChildNodes);
                }
            }
            return a;
        }传入参数是节点集合
      

  3.   

    当然这是假定你只有一个选中,如果有多个的话把string a  换成ArrayList集合
     string getString(TreeNodeCollection item) 
        { 
            ArrayList a = new ArrayList(); 
            foreach (TreeNode var in item) 
            { 
                if (var.Checked) 
                { 
                    a.Add(var.Text); 
                   
                } 
                if (var.ChildNodes.Count>0) 
                { 
                    getString(var.ChildNodes); 
                } 
            } 
            return a; 
        } 
      

  4.   

    在Button的单击事件中
     string select = "";
                foreach (Control check in this.Controls)
                {
                    if (check is CheckBox)
                    {
                        CheckBox cb = (CheckBox)check;
                        if (cb.Checked)
                        {
                            select = cb.Text + " "+select;
                        }
                    }
                }
      

  5.   

     foreach(TreeNode no  in this.tvMenu.Nodes)
                {
                    GetTree(no);
                    GetChildTree(no);
                }
     private void GetTree(TreeNode node)
            {
                if (node.Checked == true)
                {
                   int i=int.Parse(node.Value.ToString().Trim());                
                }        }
    rivate void GetChildTree(TreeNode node)
            {
                foreach (TreeNode nd in node.ChildNodes)
                {
                    if (nd.Checked)
                    {
                    
                    }
                    if(nd.ChildNodes.Count >0)
                        GetChildTree(nd);
                }
            }