473,378 Members | 1,319 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Tree View

5
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(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
PopulateRootLevel();
}
}
//select ParentId, GroupName,(select count(*) FROM tree WHERE SubGroup=sc.ParentId) SubGroup,SubGroup FROM tree sc where ParentId=@parentID
private void PopulateRootLevel()
{
SqlConnection objConn = new SqlConnection("Data Source=CDTECHPRO2\\SQLEXPRESS;Initial Catalog=Image;Integrated Security=True");
SqlCommand objCommand = new SqlCommand("select ParentId,GroupName,(select count(*) FROM tree WHERE SubGroup=sc.ParentId) childnodecount FROM tree sc where SubGroup IS NULL", objConn);
SqlDataAdapter da = new SqlDataAdapter(objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(dt, TreeView1.Nodes);
}

private void PopulateNodes(DataTable dt, TreeNodeCollection 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.PopulateOnDemand = ((int)dr["childnodecount"] > 0);
}
}

private void PopulateSubLevel(int parentid, TreeNode parentNode)
{
SqlConnection objConn = new SqlConnection("Data Source=CDTECHPRO2\\SQLEXPRESS;Initial Catalog=Image;Integrated Security=True");
SqlCommand objCommand = new SqlCommand("select ParentId,GroupName,(select count(*) FROM tree " + "WHERE SubGroup=sc.ParentId) childnodecount FROM tree sc where SubGroup=@SubGroup", objConn);
objCommand.Parameters.Add("@SubGroup", SqlDbType.Int).Value = parentid;
SqlDataAdapter da = new SqlDataAdapter(objCommand);
DataTable dt = new DataTable();
da.Fill(dt);
PopulateNodes(dt, parentNode.ChildNodes);
}

protected void TreeView1_TreeNodePopulate(object sender, TreeNodeEventArgs e)
{
int s = int.Parse(e.Node.Value);
PopulateSubLevel(s, e.Node);
}




but it should not work in C# windows application...


PopulateOnDemand insted of what method what method i am going to use to dinamically populate a data...

help my any one...
Dec 20 '07 #1
0 1064

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: imani_technology_spam | last post by:
We need to present hierarchical data on a web page, the same way the tree view shows files in Windows Explorer. Here's the catch: that tree view needs to be bound to a SQL Server database. How...
0
by: Tree menu using XML | last post by:
I have one XML file that has nodes and sub node and each and every node has the attribute call visible if its value is true then diplay this node else don't display thid node, but this condition i...
1
by: Jesper DK | last post by:
Hi, I have docked a tree view to the left on a form. When I start to populate this tree view with nodes, a horizontal scroll box appears in the bottom of the tree view even though thee tree...
3
by: Saradhi | last post by:
Hi All, Here I am facing a performance problem with the TreeView Node renaming. I am displaying a hierarchy Data in a treeview in my Windows C# Application. My tree view represents an...
1
by: Kaye | last post by:
It seems that when I dynamically resize items in a tree-view control, using TVM_SETITEM and the TVITEMEX iIntegral member, things go awry. The window draws properly, but it seems like the RECTs for...
10
by: dwok | last post by:
Does anyone know of a good article that discusses creating a "Tree View" control in ASP.NET? Or perhaps a Tree View Control that comes with source code? I have come across a lot of tree controls...
0
by: rinishrk | last post by:
Hi, I have a web application that contains subfolders Admin and User with related webpages inside them. Within the Admin folder I have a page containing a Tree View Control.I want this tree view...
3
by: gmail | last post by:
Hi Friends, Can any body suggest me on this. I am working on .NET 2005 Frame work 2.0 . I am facing problem using the tree stucture. I created the site map.Now i want use the site map in every...
1
by: BeginingOfLife | last post by:
i am using a java script to create a tree view in my html page. i got that script from this link : http://destroydrop.com/javascripts/tree/ given script is static script creations for tree...
1
by: happy.john1234 | last post by:
Hi, i have got large xml file which i have to show in tree view windows form.I tried with loading all those data at once to tree view but it took a long time to render that tree view.Now i am...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.