TreeView (1/3)
•<%@ Page Language="C#" %> TreeView
•<%@ Import Namespace="System.Data" %>
•<%@ Import Namespace="System.Data.SqlClient" %>
–<script runat="server">
–const string conexao = "Server=localhost;Database=Northwind;user id=sa";
–void Page_Load()
–{
•if (! Page.IsPostBack)
• FillNodes();
• }
• void FillNodes()
• {
•DataSet dst = GetData();
•foreach (DataRow masterRow in dst.Tables["Categories"].Rows)
• {
–TreeNode masterNode = new TreeNode((string)masterRow["CategoryName"]);
–TreeView1.Nodes.Add(masterNode);
–foreach (DataRow childRow in masterRow.GetChildRows("Children"))
• {
»TreeNode childNode = new TreeNode((string)childRow["ProductName"]);
»masterNode.ChildNodes.Add(childNode);
• }
• }
• }