Musafir

Hi..

I wanted to create a tree view which gets populated from the database. I had used the code from the website:

As i dont use a stored procedure, i had used the query itself. But i am not getting the tree view in the browser.
My changed code is:

Code in default.aspx page

****************************

using System;

using System.Data;

using System.Configuration;

using System.Web;

using System.Web.Security;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page

{

public void GetProductCategories(TreeNode node)

{

WarehouseDB.CategoryList categories = WarehouseDB.GetProductCategories();

foreach (WarehouseDB.Category c in categories)

{

TreeNode newNode = new TreeNode(c.Name, c.Id);

newNode.SelectAction = TreeNodeSelectAction.Expand;

newNode.PopulateOnDemand = true;

node.ChildNodes.Add(newNode);

}

}

public void PopulateNode(Object source, TreeNodeEventArgs e)

{

switch (e.Node.Depth)

{

case 0:

GetProductCategories(e.Node);

break;

}

}

code in WarehouseDB.cs file

***********************************

public class WarehouseDB

{

public static CategoryList GetProductCategories()

{

CategoryList cat = new CategoryList();

String connStr = ConfigurationManager.AppSettings.GetValues("Connectionsql").ToString();

string GetCategories = "select row_id,name from Categories";

SqlDataSource mySource = new SqlDataSource(connStr, "GetCategories");

mySource.SelectCommandType = SqlDataSourceCommandType.Text;

IEnumerable result = mySource.Select(DataSourceSelectArguments.Empty);

foreach (DataRowView row in result)

{

cat.Add(new Category(row["row_id"].ToString(),row["name"].ToString()));

}

return cat;

}

public class Category

{

public String Id;

public String Name;

public Category(String id, String name)

{

this.Id = id;

this.Name = name;

}

}

public class CategoryList : ArrayList

{

public new Category this[int i]

{

get

{

return (Category)baseIdea;

}

set

{

baseIdea = value;

}

}

}

}

what is wrong in the above code why i am not getting the tree in the browser please help



Re: Windows Forms General sample database

oxi

Where can I get a sample database containing a strored procedure for this example code
Example code without sample database can be found here: http://quickstarts.asp.net/QuickStartv20/util/srcview.aspx path=~/aspnet/samples/ctrlref/navigation/TreeView/TreeView11.src