Results 1 to 2 of 2

Thread: Populate a treeview -web-

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Santo Domingo,D.N., Dom. Rep.
    Posts
    707

    Populate a treeview -web-

    VB Code:
    1. void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
    2.         {
    3.             SqlConnection cn = new SqlConnection(Cnstring);
    4.             string SqlString = "Select CHR_ROOT, CHR_DESCRIPCION from SIS_MATRIZ_MENU Order by chr_root";
    5.             SqlCommand cmd = new SqlCommand(SqlString, cn);
    6.             cn.Open();
    7.             using (cn)
    8.             {
    9.                 SqlDataReader reader = cmd.ExecuteReader();
    10.                 while (reader.Read())
    11.                 {
    12.                     TreeNode newNode = new TreeNode();
    13.                     newNode.PopulateOnDemand = true;
    14.                     newNode.Text = reader["CHR_DESCRIPCION"].ToString();
    15.                     newNode.Value = reader["CHR_ROOT"].ToString();
    16.                     e.Node.ChildNodes.Add(newNode);
    17.                 }
    18.             }
    19.         }

    This code is to populate a treeview.
    I want to:
    1. Run this code as soon as the page is loaded or
    2. Run the TreeView1_TreeNodePopulate from anywhere

    How can i do this

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Populate a treeview -web-

    I take it you are using ASP.NET 2.0, which is information that you should probably include rather than us having to investigate to find out. That is an event handler for the TreeNodePopulate event of TreeNode1, so it is intended to be executed when that event is raised. If you want to execute that code other times then you should take it out of that event handler and put it in another method, which you can then call from that event handler, the form's Load event handler or anywhere else.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width