Is it possible to show the Treeview in a list box
Tree View
Collapse
X
-
i want to populate a data from a data base..
i wrote a code for webapplication aspx.cs.. which is perfectly work's
code is
protected void Page_Load(objec t sender, EventArgs e)
{
if (!Page.IsPostBa ck)
{
PopulateRootLev el();
}
}
//select ParentId, GroupName,(sele ct count(*) FROM tree WHERE SubGroup=sc.Par entId) SubGroup,SubGro up FROM tree sc where ParentId=@paren tID
private void PopulateRootLev el()
{
SqlConnection objConn = new SqlConnection(" Data Source=CDTECHPR O2\\SQLEXPRESS; Initial Catalog=Image;I ntegrated Security=True") ;
SqlCommand objCommand = new SqlCommand("sel ect ParentId,GroupN ame,(select count(*) FROM tree WHERE SubGroup=sc.Par entId) childnodecount FROM tree sc where SubGroup IS NULL", objConn);
SqlDataAdapter da = new SqlDataAdapter( objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(d t, TreeView1.Nodes );
}
private void PopulateNodes(D ataTable dt, TreeNodeCollect ion nodes)
{
foreach (DataRow dr in dt.Rows)
{
TreeNode tn = new TreeNode();
tn.Text = dr["GroupName"].ToString();
tn.Value = dr["ParentId"].ToString();
nodes.Add(tn);
//If node has child nodes, then enable on-demand populating
tn.PopulateOnDe mand = ((int)dr["childnodecount "] > 0);
}
}
private void PopulateSubLeve l(int parentid, TreeNode parentNode)
{
SqlConnection objConn = new SqlConnection(" Data Source=CDTECHPR O2\\SQLEXPRESS; Initial Catalog=Image;I ntegrated Security=True") ;
SqlCommand objCommand = new SqlCommand("sel ect ParentId,GroupN ame,(select count(*) FROM tree " + "WHERE SubGroup=sc.Par entId) childnodecount FROM tree sc where SubGroup=@SubGr oup", objConn);
objCommand.Para meters.Add("@Su bGroup", SqlDbType.Int). Value = parentid;
SqlDataAdapter da = new SqlDataAdapter( objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(d t, parentNode.Chil dNodes);
}
protected void TreeView1_TreeN odePopulate(obj ect sender, TreeNodeEventAr gs e)
{
int s = int.Parse(e.Nod e.Value);
PopulateSubLeve l(s, e.Node);
}
but it should not work in C# windows application...
PopulateOnDeman d insted of what method what method i am going to use to dinamically populate a data... and this event is also not alaliable..
protected void TreeView1_TreeN odePopulate(obj ect sender, TreeNodeEventAr gs e)Comment
Comment