首页 新闻 会员 周边 捐助

树状选择控件

0
悬赏园豆:5 [已解决问题] 解决于 2013-08-21 15:36

我用treeview绑定了数据库的数据,但是上级说太简单了 只绑定几个数据他怎么用呢 所以一般的树状选择控件都具有哪些功能的。用.net js jquery都行的。

camille繁花的主页 camille繁花 | 初学一级 | 园豆:16
提问于:2013-08-21 10:28
< >
分享
最佳答案
0
收获园豆:5
dudu | 高人七级 |园豆:30778 | 2013-08-21 11:02
其他回答(2)
0

zTree,功能够多,够强大~

幻天芒 | 园豆:37207 (高人七级) | 2013-08-21 10:59

刚看到一篇Ztree的博文:Ztree之初涉——简单Ztree的实现

支持(0) 反对(0) dudu | 园豆:30778 (高人七级) | 2013-08-21 12:16
0

 <script type="text/javascript" language="javascript">
         function postBackByObject(event) {
             var o = (window.event) ? window.event.srcElement : event.target;
             if (o.nodeName == "INPUT" && o.type == "checkbox") {
                 __doPostBack("", "");
             }
         }
    </script>      

 

 

protected void Page_Load(object sender, EventArgs e)
        {
            TreeView1.EnableClientScript = true;
            TreeView1.Attributes.Add("onclick", "postBackByObject(event)");

            if (!IsPostBack)
            {

                DataSet ds = new TaxiRadarBasicInfo.BLL.TaxiCityCode().GetRegionAllList();
                TreeView treeview = new TreeView();

                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    TreeNode trP = new TreeNode();
                    trP.Text = row["CityName"].ToString();
                    trP.Value = row["CityCode"].ToString();
                    //TreeCAdd(trP, row["CityCode"].ToString());
                    trP.Expanded = false;
                    TreeView1.Nodes.Add(trP);
                    TreeCAdd(trP);
                }
            }
        }

        public void TreeCAdd(TreeNode trP)
        {
            string CityCode = trP.Value;
            DataSet ds = new TaxiRadarBasicInfo.BLL.TaxiCityCode().GetCarRegionByTerminalSN(CityCode);

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                TreeNode trC = new TreeNode();
                trC.Text = row["Brand"].ToString();
                trC.Value = row["TerminalSN"].ToString();
                trP.ChildNodes.Add(trC);
            }
        }

        protected void TreeView1_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
        {
            RecursiveCheckCheckBox(e.Node, e.Node.Checked, true);
            TreeNode current = e.Node;
            while (!current.Checked && current.Parent != null && !IsChildNodesChecked(current.Parent))
            {
                current.Parent.Checked = false;
                current = current.Parent;
            }
            if (e.Node.Checked)
            {
                RecursiveCheckCheckBox(e.Node, e.Node.Checked, false);
            }
        }


        private bool IsChildNodesChecked(TreeNode n)
        {
            bool result = false;
            if (n.ChildNodes.Count == 0)
            {
                result = n.Checked;
            }
            foreach (TreeNode t in n.ChildNodes)
            {
                if (result |= t.Checked)
                {
                    break;
                }
            }
            return result;
        }


        private void RecursiveCheckCheckBox(TreeNode n, bool isChecked, bool topDown)
        {
            if (topDown)
            {
                foreach (TreeNode l in n.ChildNodes)
                {
                    l.Checked = isChecked;
                    if (l.ChildNodes.Count != 0)
                    {
                        RecursiveCheckCheckBox(l, isChecked, topDown);
                    }
                }
            }
            else
            {
                n.Checked = isChecked;
                if (n.Parent != null)
                {
                    RecursiveCheckCheckBox(n.Parent, isChecked, false);
                }
            }
        }

camille繁花 | 园豆:16 (初学一级) | 2013-08-21 15:34
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册