TreeView (3/3)
•<script runat="server">
–string conexao = "Database=northwind;server=(local);user id=sa";
–void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
–{
•SqlConnection con = new SqlConnection(conexao);
•string sql = "SELECT EmployeeID, FirstName FROM Employees";
•SqlCommand cmd = new SqlCommand(sql, con);
•con.Open();
•using (con)
•{
–SqlDataReader reader = cmd.ExecuteReader();
–while (reader.Read())
–{
»TreeNode newNode = new TreeNode();
»newNode.PopulateOnDemand = true;
»newNode.Text = reader["FirstName"].ToString();
»newNode.Value = reader["EmployeeID"].ToString();
»e.Node.ChildNodes.Add(newNode);
• }
• }
• }