protected void Page_Load(object sender, EventArgs e)
    {
        bandtree("0");
    }

    public void bandtree(string seldate)
    {
        DataTable dataTable = bind().Tables[0];
        TreeView1.Nodes.Clear();
        DataRow[] rowList = dataTable.Select("parentid='0'");
        if (rowList.Length < 0)
            return;
        TreeNode rootNode = new TreeNode();
        rootNode.Text = rowList[0]["nodename"].ToString();
        rootNode.Value = rowList[0]["nodeid"].ToString();
        rootNode.Expanded = true;
        TreeView1.Nodes.Add(rootNode);
        childnode(rootNode,seldate);
    }
    private DataSet bind()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ConnectionString);
        con.Open();
        SqlDataAdapter sda = new SqlDataAdapter("select * from treeviewtable",con);
        DataSet ds = new DataSet();
        sda.Fill(ds);
        return ds;
    }

    private void childnode(TreeNode parentNode, string seldate)
    {
        DataTable datatable1 = bind().Tables[0];
        DataRow[] rowlist = datatable1.Select("parentid='"+parentNode.Value+"'");
        foreach (DataRow row in rowlist)
        {
            TreeNode node = new TreeNode();
            node.Text = row["nodename"].ToString();
            node.Value = row["nodeid"].ToString();
            node.NavigateUrl=row["url"].ToString();
            node.Expanded = true;
            parentNode.ChildNodes.Add(node);
            childnode(node, seldate);
        }
    }