for populating tree view (products grouped by category) i have used below stored procedures and code , but when i run ,without any error i have nothing on the page (does not show), please help what is the problem
create PROCEDURE [dbo].[getCat]
AS
select * from Categories
order by CategoryID
create PROCEDURE [dbo].[getProductsbyCat]
AS
SELECT p.ProductID, p.ProductName,c.CategoryID,c.CategoryName
FROM Products p
JOIN Categories c ON p.CategoryID = c.CategoryID
ORDER BY c.CategoryID
the cs code is like below:
public partial class Default3 : System.Web.UI.Page
{
private DataClassesDataContext _DataContext;
protected void Page_Load(object sender, EventArgs e)
{
_DataContext = new DataClassesDataContext();
TreeView tree = new TreeView();
var result_cat = from c in _DataContext.getCat()
select c;
foreach (var parentItem in result_cat)
{
var categoryItem = new TreeNode();
categoryItem.Text = parentItem.CategoryName;
categoryItem.PopulateOnDemand = true;
categoryItem.CollapseAll();
categoryItem.SelectAction = TreeNodeSelectAction.None;
var result_sub_cat = from s in _DataContext.getProductsbyCat()
where s.CategoryID == parentItem.CategoryID
select s;
foreach (var childItem in result_sub_cat)
{
var childrenItem = new TreeNode();
childrenItem.Text = childItem.ProductName;
categoryItem.ChildNodes.Add(childrenItem);
categoryItem.SelectAction = TreeNodeSelectAction.SelectExpand;
}
tree.CollapseAll();
tree.Nodes.Add(categoryItem);
}
}
}
masoud-s
Member
81 Points
196 Posts
tree view populating
Nov 20, 2012 03:28 PM|LINK
for populating tree view (products grouped by category) i have used below stored procedures and code , but when i run ,without any error i have nothing on the page (does not show), please help what is the problem
the cs code is like below:
public partial class Default3 : System.Web.UI.Page { private DataClassesDataContext _DataContext; protected void Page_Load(object sender, EventArgs e) { _DataContext = new DataClassesDataContext(); TreeView tree = new TreeView(); var result_cat = from c in _DataContext.getCat() select c; foreach (var parentItem in result_cat) { var categoryItem = new TreeNode(); categoryItem.Text = parentItem.CategoryName; categoryItem.PopulateOnDemand = true; categoryItem.CollapseAll(); categoryItem.SelectAction = TreeNodeSelectAction.None; var result_sub_cat = from s in _DataContext.getProductsbyCat() where s.CategoryID == parentItem.CategoryID select s; foreach (var childItem in result_sub_cat) { var childrenItem = new TreeNode(); childrenItem.Text = childItem.ProductName; categoryItem.ChildNodes.Add(childrenItem); categoryItem.SelectAction = TreeNodeSelectAction.SelectExpand; } tree.CollapseAll(); tree.Nodes.Add(categoryItem); } } }niksv
Contributor
5925 Points
1115 Posts
Re: tree view populating
Nov 20, 2012 07:10 PM|LINK
At the end you have not added treeview (tree variable) to the form's controls collection.