Re: TreeView Caching
- From: "Bishop" <nospam@xxxxxxxxxx>
- Date: Wed, 7 Mar 2007 16:40:11 -0600
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" <nospam@xxxxxxxxxx> wrote in message
news:%23tvu3U1WHHA.5068@xxxxxxxxxxxxxxxxxxxxxxx
This got me on the right course, thanks!
"brians[MCSD]" <briansMCSD@xxxxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:110E315D-EE3F-4B79-8346-DEE1FCA887C6@xxxxxxxxxxxxxxxx
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.
.
- Prev by Date: insert item / review
- Next by Date: Re: dot net - uploading photos query - help / comments / suggestions
- Previous by thread: insert item / review
- Next by thread: RE: TreeView caching
- Index(es):
Relevant Pages
|