Click here to Skip to main content
15,991,072 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am new to using C# but I am working with code that someone has designed a dynamically populated asp:treeview. I need to be able to retrieve the values from the checkboxes and save them to the database. Here is a sample of the front end code:

<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>



Here is how the sub catagory is populated:
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);
    }
  }
}


I am attempting to save it as a normal checkbox but ran into trouble. Any assistance would be highly appreciated

[Modified: others added the pre tags. Fixed the tabbing.]
Posted
Updated 9-Jul-10 10:15am
v3
Comments
TheyCallMeMrJames 9-Jul-10 16:05pm    
What is the trouble you are running into? You have the code listing for the generation here, but not what you're doing to save. Are you running into an error?
William Winner 9-Jul-10 16:16pm    
is it just me, or are there some extra > tags in the asp code?

Also, you said you "ran into trouble". You're going to have to describe the trouble a little more in detail. What kind of trouble?
SaltyB 9-Jul-10 17:15pm    
ran into trouble, meant I didnt know what I was doing. I am just looking for a method to save the values from treeview nodes

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900