Sunday, April 18, 2010
I almost want to self-inflict some wounds just to try this out
http://link.brightcove.com/services/player/bcpid38324044001?bctid=77593817001
Sunday, February 21, 2010
Recursive method for use with a flat parent - child table and .net treeview
Ok, I scoured the net for a while today and found all these crazy ideas to turn a simple 3 column table [id], [parentid], [name] self-referencing table into a infinite depth .net treeview. I found some ideas within SQL with some very elaborate looping schemes, temp tables and cursors. I found some ideas within C#, but using multiple datasets, and multiple sql connections being made. I did not, however, find anything as simple as what I came up with, and I feel I need to share this with the world in hopes that a search engine finds my solution for someone who needs a quick and simple solution.
Being that the free .Net TreeView control does not implement a built in recursion method where you can simply bind a datasource structured like I mention above to it, we have to add child nodes of parent node at runtime. Assuming you are in the same boat as I am/was.
Being that the free .Net TreeView control does not implement a built in recursion method where you can simply bind a datasource structured like I mention above to it, we have to add child nodes of parent node at runtime. Assuming you are in the same boat as I am/was.
So using that data structure above. I simple placed a TreeView control on the page (*with some simple styles of course)
I then create the recursive method that does the work.
protected void GetKids(TreeNode parentNode, string parentid, DataTable srcTable)
{
DataRow[] dr = srcTable.Select("org_parent_id=" + parentid);
foreach(DataRow cr in dr)
{
TreeNode newnode = new TreeNode();
newnode.Text = cr["org_name"].ToString();
newnode.Value = cr["org_id"].ToString();
parentNode.ChildNodes.Add(newnode);
GetKids(newnode, cr["org_id"].ToString(), srcTable);
}
}
This method takes in the parentNode object, the parentid as a string from that table structure I mentioned above and the datatable which has all the source data in it. Note the last line in this method is a call to itself passing in the id and node of the record currently being processed.
On the Page_Load, I simply then do this...
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BusinessObject.DataClasses.Organization Organization = new BusinessObject.DataClasses.Organization();
DataTable dt = Organization.GetOrgStructure(); //Get the org structure table here
DataRow[] dr = dt.Select();
TreeNode tr = new TreeNode();
tr.Text = "Company"; //Top Level Org Unit
tr.Value = "16"; //ID of Top Level Org Unit
tvOrg.Nodes.Add(tr);
GetKids(tr, "16", dt);
}
}
I'm sure this even could be simplified, streamlined and cut down on resources further. I found no samples on the net like this, but was able to think it up in just a few minutes after putting my head on...
Wednesday, November 19, 2008
Comedy Central bit on Jeff Han's multitouch screens
CNN's power tool for visualizing the election results is one of Jeff Han's multitouch screens. The Daily Show does a skit on it here...
Monday, November 17, 2008
Subscribe to:
Posts (Atom)
