• about treeview


    using ..;

    namespace WebApp
    {
        
    public partial class _Default : System.Web.UI.Page
        
    {
            TreeNode node;

            
    protected void Page_Load(object sender, EventArgs e)
            
    {
                
                BindTree();
            }
           

           

            
    private void BindTree()
            
    {
                
    string cmdText = "SELECT AreaID,Name FROM Area WHERE substring(AreaID,3,4)='0000'";

                
    using (SqlDataReader dr = SqlHelper.ExcuteReader(ConfigurationManager.ConnectionStrings["SqlConn"].ConnectionString, cmdText, null))
                
    {
                    
    while (dr.Read())
                    
    {
                        node 
    = new TreeNode();

                        node.Text 
    = dr.GetString(1);
                        node.Value 
    = dr.GetString(0);
                        node.NavigateUrl 
    = "page.html?id=" + dr.GetString(0);
                        node.Target 
    = "_blank";

                        TreeView1.Nodes.Add(node);

                        GetChilds(dr.GetString(
    0));
                    }

                }

               
            }


            
    private void GetChilds(string parentid)
            
    {
                
    string cmdText = "SELECT AreaID,Name FROM Area WHERE substring(AreaID,1,2)='" + parentid.Substring(02+ "' AND substring(AreaID,5,2)='00'";

                
    using (SqlDataReader dr = SqlHelper.ExcuteReader(ConfigurationManager.ConnectionStrings["SqlConn"].ConnectionString, cmdText, null))
                
    {
                    
    while (dr.Read())
                    
    {
                        TreeNode cnode 
    = new TreeNode();

                        cnode.Text 
    = dr.GetString(1);
                        cnode.NavigateUrl 
    = "subpage.html?id="+dr.GetString(0);
                        cnode.Target 
    = "_blank";

                        node.Expanded 
    = false;                    
                        node.ChildNodes.Add(cnode);
                    }

                }

            }


            
    protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
            
    {
                TreeView1.SelectedNode.Expanded 
    = true;
            }

        }

    }
  • 相关阅读:
    NOIP模拟测试2「排列 (搜索)·APIO划艇」
    Linux运维基础
    Linux之权限详解
    Linux之特殊符号与正则表达式
    Linux之命令进阶
    Linux分区的几种方案
    开启MySQL远程访问权限 允许远程连接
    Linux命令
    win10 激活(亲测可用)
    帮你解决无法早起的焦虑-顺便撸羊毛
  • 原文地址:https://www.cnblogs.com/yiki/p/777250.html
Copyright © 2020-2023  润新知