<asp:treeview id="tvCategories" xmlns:asp="#unknown"> Font-Names="Arial" ForeColor="Blue" EnableClientScript="true" PopulateNodesFromClient="true" OnTreeNodePopulate="PopulateNode" runat="server"> <asp:treenode text="Product Categories"> SelectAction="SelectExpand" PopulateOnDemand="true" /> </asp:treenode> </asp:treeview></asp:treenode></asp:treeview>
void PopulateSubCategories(TreeNode node) { // Query for the product categories. These are the values // for the second-level nodes. DataSet ResultSet = RunQuery("Select ProductCategoryId, Category From ProductCategory" + " Where ParentCategoryId=" + node.Value); // Create the second-level nodes. if (ResultSet.Tables.Count > 0) { // Iterate through and create a new node for each row in the query results. // Notice that the query results are stored in the table of the DataSet. foreach (DataRow row in ResultSet.Tables[0].Rows) { // Create the new node. Notice that the CategoryId is stored in the Value property // of the node. This will make querying for items in a specific category easier when // the third-level nodes are created. TreeNode newNode = new TreeNode(); newNode.Text = row["Category"].ToString(); newNode.Value = row["ProductCategoryId"].ToString(); // Set the PopulateOnDemand property to true so that the child nodes can be // dynamically populated. newNode.PopulateOnDemand = true; // Set additional properties for the node. newNode.SelectAction = TreeNodeSelectAction.Expand; newNode.ShowCheckBox = true; // Add the new node to the ChildNodes collection of the parent node. node.ChildNodes.Add(newNode); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)