473,396 Members | 1,833 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,396 software developers and data experts.

TreeView Caching

I have a treeview in my master page. It's built off a sql table that looks
like this:
TreeID, Name, ParentID
1,shoes,0
2,boots,0
3,slippers,0
4,shoe laces, 1
5, shoe soles, 1
6, boot laces, 2
7, slipper ears, 3
8, slipper ears blue, 7

To populate I do a number of small sql queries. The data is dynamic but
typically will change no more than once a day.

I'm looking for suggestions on how I can cache the treeview so it only runs
the queries a few times a day instead of each time the page loads.
Feb 27 '07 #1
3 4724
Hello Bishop,

One way to do this would be to cache the TreeNodeCollection which is
attached to the TreeView. Something along the lines of the following:

=-=-=-=-
protected void LoadTreeView()
{
TreeNodeCollection tnc;

if (Cache["tnc"] == null) // treenodes not in cache
{
// this is where you load the data from SQL before it's cached.
// in this sample, I'm building the treenode collection
// dynamically.
TreeNodeCollection tncNew = new TreeNodeCollection();

for (int i = 0; i < 5; i++)
{
TreeNode tn = new TreeNode("Node" + i.ToString());
for (int j = 0; j < 3; j++)
{
TreeNode tnChild = new TreeNode("ChildNode" +
j.ToString());
tn.ChildNodes.Add(tnChild);
}
tncNew.Add(tn);
}
// Add it to the cache
Cache.Add("tnc", tncNew, null, DateTime.Now.AddMinutes(2),
TimeSpan.Zero, CacheItemPriority.High, null);
tnc = tncNew;
}
else // treenodes have been cached
{
// Get the collection from the cache
tnc = (TreeNodeCollection) Cache["tnc"];
}
foreach (TreeNode tn in tnc)
{
// TreeView1 is the control id
TreeView1.Nodes.Add(tn);
}
}
--
enjoy - brians
http://www.limbertech.com
"Bishop" wrote:
I have a treeview in my master page. It's built off a sql table that looks
like this:
TreeID, Name, ParentID
1,shoes,0
2,boots,0
3,slippers,0
4,shoe laces, 1
5, shoe soles, 1
6, boot laces, 2
7, slipper ears, 3
8, slipper ears blue, 7

To populate I do a number of small sql queries. The data is dynamic but
typically will change no more than once a day.

I'm looking for suggestions on how I can cache the treeview so it only runs
the queries a few times a day instead of each time the page loads.
Feb 27 '07 #2
This got me on the right course, thanks!

"brians[MCSD]" <br********@discussions.microsoft.comwrote in message
news:11**********************************@microsof t.com...
Hello Bishop,

One way to do this would be to cache the TreeNodeCollection which is
attached to the TreeView. Something along the lines of the following:

=-=-=-=-
protected void LoadTreeView()
{
TreeNodeCollection tnc;

if (Cache["tnc"] == null) // treenodes not in cache
{
// this is where you load the data from SQL before it's cached.
// in this sample, I'm building the treenode collection
// dynamically.
TreeNodeCollection tncNew = new TreeNodeCollection();

for (int i = 0; i < 5; i++)
{
TreeNode tn = new TreeNode("Node" + i.ToString());
for (int j = 0; j < 3; j++)
{
TreeNode tnChild = new TreeNode("ChildNode" +
j.ToString());
tn.ChildNodes.Add(tnChild);
}
tncNew.Add(tn);
}
// Add it to the cache
Cache.Add("tnc", tncNew, null, DateTime.Now.AddMinutes(2),
TimeSpan.Zero, CacheItemPriority.High, null);
tnc = tncNew;
}
else // treenodes have been cached
{
// Get the collection from the cache
tnc = (TreeNodeCollection) Cache["tnc"];
}
foreach (TreeNode tn in tnc)
{
// TreeView1 is the control id
TreeView1.Nodes.Add(tn);
}
}
--
enjoy - brians
http://www.limbertech.com
"Bishop" wrote:
>I have a treeview in my master page. It's built off a sql table that
looks
like this:
TreeID, Name, ParentID
1,shoes,0
2,boots,0
3,slippers,0
4,shoe laces, 1
5, shoe soles, 1
6, boot laces, 2
7, slipper ears, 3
8, slipper ears blue, 7

To populate I do a number of small sql queries. The data is dynamic but
typically will change no more than once a day.

I'm looking for suggestions on how I can cache the treeview so it only
runs
the queries a few times a day instead of each time the page loads.

Feb 28 '07 #3
I'm having a weird issue with caching the treeview and the problem is not
exibited in IE only in FireFox. Everything looks like it's working except
it dosn't let me expand the listings. If I set the treeview to fully
expand, I see all the nodes but the compress (un-expand?) dosn't work. From
what I can tell the javascript tags are not getting put in when it's being
displayed from cache. Below is the code I'm using. Any thoughts
appreciated.

If (IsNothing(Cache("Tree-" &
Replace(Request.ServerVariables("SERVER_NAME"), "www.", "")))) Then

popTree(Session("SiteID"))

Dim myTreeNodeCollection As TreeNodeCollection = trvCategories.Nodes

Dim myTreeNodeArray(myTreeNodeCollection.Count - 1) As TreeNode

myTreeNodeCollection.CopyTo(myTreeNodeArray, 0)

Cache.Insert("Tree-" & Replace(Request.ServerVariables("SERVER_NAME"),
"www.", ""), myTreeNodeArray, Nothing, DateTime.Now.AddMinutes(15),
TimeSpan.Zero)

Else

Dim myTreeNodeArray() As TreeNode

myTreeNodeArray = Cache("Tree-" &
Replace(Request.ServerVariables("SERVER_NAME"), "www.", ""))

Dim myNode As TreeNode

For Each myNode In myTreeNodeArray

myNode.Text = myNode.Text

trvCategories.Nodes.Add(myNode)

Next

End If



"Bishop" <no****@nospam.comwrote in message
news:%2****************@TK2MSFTNGP03.phx.gbl...
This got me on the right course, thanks!

"brians[MCSD]" <br********@discussions.microsoft.comwrote in message
news:11**********************************@microsof t.com...
>Hello Bishop,

One way to do this would be to cache the TreeNodeCollection which is
attached to the TreeView. Something along the lines of the following:

=-=-=-=-
protected void LoadTreeView()
{
TreeNodeCollection tnc;

if (Cache["tnc"] == null) // treenodes not in cache
{
// this is where you load the data from SQL before it's
cached.
// in this sample, I'm building the treenode collection
// dynamically.
TreeNodeCollection tncNew = new TreeNodeCollection();

for (int i = 0; i < 5; i++)
{
TreeNode tn = new TreeNode("Node" + i.ToString());
for (int j = 0; j < 3; j++)
{
TreeNode tnChild = new TreeNode("ChildNode" +
j.ToString());
tn.ChildNodes.Add(tnChild);
}
tncNew.Add(tn);
}
// Add it to the cache
Cache.Add("tnc", tncNew, null, DateTime.Now.AddMinutes(2),
TimeSpan.Zero, CacheItemPriority.High, null);
tnc = tncNew;
}
else // treenodes have been cached
{
// Get the collection from the cache
tnc = (TreeNodeCollection) Cache["tnc"];
}
foreach (TreeNode tn in tnc)
{
// TreeView1 is the control id
TreeView1.Nodes.Add(tn);
}
}
--
enjoy - brians
http://www.limbertech.com
"Bishop" wrote:
>>I have a treeview in my master page. It's built off a sql table that
looks
like this:
TreeID, Name, ParentID
1,shoes,0
2,boots,0
3,slippers,0
4,shoe laces, 1
5, shoe soles, 1
6, boot laces, 2
7, slipper ears, 3
8, slipper ears blue, 7

To populate I do a number of small sql queries. The data is dynamic but
typically will change no more than once a day.

I'm looking for suggestions on how I can cache the treeview so it only
runs
the queries a few times a day instead of each time the page loads.


Mar 7 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: CJM | last post by:
I've had some periodic problems on certain (intranet)servers where IIS seems to be caching thing in an unexpected way, or is server cached pages where new content is expected. The first...
42
by: lauren quantrell | last post by:
So many postings on not to use the treeview control, but nothing recently. Is it safe to swim there yet with Access 2000-Access 2003?
0
by: Mike Szanto | last post by:
This post is intended to provide a possible solution to a problem with the Internet Explorer TreeView WebControl where it locks up or freezes when you try to open a treeview node. I experienced...
6
by: L.M | last post by:
Hello, I knew how to use the treeview under VB6. After migrating to .NET, well, I'm lost. I try to add a new node, either to the same level or as a child to a selected node in the treeview....
14
by: Mr.D | last post by:
How do I save/load the contents of a Treeview to a file? I have found several good examples written i VB6, but not a single one for VB.NET. Please help. ---- Tim
0
by: Clinton Ingram | last post by:
I have a simple aspx page running on the RTM .NET Framework 2.0 on Windows Server 2003 SP1 that has a TreeView, some Validation controls and some ImageButtons. The page was returning slowly for...
0
by: BillE | last post by:
PROBLEM SUMMARY -- I use "Response.Cache.SetCacheability(HTTPCacheability.NoCache)" to force a page to reload instead of displaying cached content. However, I don't really want to reload the...
1
by: Charlie | last post by:
Hi: This is driving me nuts. My TreeView won't show any changes/additions unless I restart visaul studio. When I requery datasource (xmldatasource control) new data is there, but tree must be...
3
by: =?Utf-8?B?TGVzbGll?= | last post by:
Using Visual Studio 2005 SP1 I am attempting to dynamically load a treeview control. I create an XmlDataSource and then load the data source using XmlDataSource.Data. I Load my XML string into...
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:
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.