TreeView效率问题 [英] TreeView efficiency problem
问题描述
我的网页性能有问题.我正在使用LINQ/SQL Server 2008/C#/.Net 4.0
.
页面上的控件列表:
母版页:
#具有DataList的Web用户控件(WUC)
#WUC具有TreeView控件.
#ContentPlaceHolder
主页(默认页面或内容页面)
#具有DataList的WUC和具有GridView且具有少量按钮的另一个嵌套WUC.
.................
问题:
1.我的主页变得很沉重.为什么?
2.尚未应用缓存.我想在页面上应用缓存.问题是,页面上的每个内容都是动态的.我想我将不得不应用缓存的缓存依赖"类型.请告知我应该在哪里应用缓存以及应该实现哪种类型的缓存.
3.如果我将DataSet放在缓存中,请提出充分的建议,以提高TreeView控件的性能.
4.如果需要使用SiteMap绑定TreeView控件,应如何动态地使用DataSet填充SiteMap?我的桌子有时会有信息变动..所以我希望它是动态的...
5.请告诉我应为此页面申请的缓存类型.
我正在如下填充TreeView:
Hi,
I am having issue with Performance of webpage. I am using LINQ / SQL server 2008 / C# / .Net 4.0
.
List of Controls on the pages:
Master Page:
# Web User Control ( WUC) having DataList
# WUC having TreeView control.
# ContentPlaceHolder
Home Page ( Default page or Content page)
# WUC having DataList and another nested WUC having GridView with few buttons.
.................
Issues:
1. My home page became very heavy. Why?
2. No Cacheing is applied yet. I want to apply cacheing on the page.. Problem is, every content on the page is Dynamic .I think I will have to apply Cache Dependency type of Cacheing. Please advice me Where should I apply cacheing and Which type of Cacheing I should implement.
3. If I put DataSet in cache Please advice will that be sufficient to increase the performance of TreeView controls.
4. If I need to use SiteMap to bind TreeView control, How should I populate SiteMap with DataSet Dynamically? I have table having Information which chnages sometimes.. So I want it to be dynamic...
5. Please advice me the types of Caching I should apply for this page.
I am populating the TreeView as followes:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
public partial class admin_WUCCatListNav : System.Web.UI.UserControl
{
booksDataContext obj = new booksDataContext();
protected void Page_Load(object sender, EventArgs e)
{
GetParentNode();
}
public void GetParentNode()
{
TreeView1.Nodes.Clear();
TreeView1.ShowLines = true;
DataSet DS= new DataSet();
DS= obj.DspBookCatBookCatDet();
TreeNode HeaderNode = new TreeNode("Categories");
HeaderNode.NavigateUrl = "Default.aspx";
for (Int32 i = 0; i < DS.Tables[0].Rows.Count; i++)
{
TreeNode PNode = new TreeNode();
TreeNode CNode = new TreeNode();
String catnam1=Convert.ToString(DS.Tables[0].Rows[i]["catnam"]);
String catcod1 = Convert.ToString(DS.Tables[0].Rows[i]["catcod"]);
Int32 j = i;
PNode.Text = catnam1;
PNode.Value = catcod1;
PNode.NavigateUrl = "frmbookbycat.aspx?catcod=" + PNode.Value;
CNode.Text = Convert.ToString(DS.Tables[0].Rows[i]["catdetnam"]) + "(" + Convert.ToString(CountBooks(Convert.ToInt32(DS.Tables[0].Rows[i]["catdetcod"]))) + ")";
CNode.Value = Convert.ToString(DS.Tables[0].Rows[i]["catdetcod"]);
CNode.NavigateUrl = "frmbookbycat.aspx?catcod=" + Convert.ToString(DS.Tables[0].Rows[i]["catcod"]) + "&catdetcod=" + CNode.Value;
//CNode.NavigateUrl = "frmbookdets.aspx?catdetcatcod=" + Convert.ToString(DS.Tables[0].Rows[i]["catdetcatcod"]) + "&catnam=" + PNode.Text;
PNode.ChildNodes.Add(CNode);
while(j < DS.Tables[0].Rows.Count-1)
{
String catnam2 = Convert.ToString(DS.Tables[0].Rows[j+1]["catnam"]);
if (catnam2 == catnam1)
{
TreeNode CNode1 = new TreeNode();
CNode1.Text = Convert.ToString(DS.Tables[0].Rows[j + 1]["catdetnam"]) + "(" + Convert.ToString(CountBooks(Convert.ToInt32(DS.Tables[0].Rows[j+1]["catdetcod"])))+ ")";
CNode1.Value = Convert.ToString(DS.Tables[0].Rows[j+1]["catdetcod"]);
CNode1.NavigateUrl = "frmbookbycat.aspx?catcod=" + Convert.ToString(DS.Tables[0].Rows[j + 1]["catcod"]) + "&catdetcod=" + CNode1.Value;
//CNode1.NavigateUrl = "frmbookdets.aspx?catdetcatcod=" + Convert.ToString(DS.Tables[0].Rows[j + 1]["catdetcatcod"]) + "&catnam=" + PNode.Text;
PNode.ChildNodes.Add(CNode1);
i = j + 1;
catnam1 = catnam2;
j++;
}
else
{
break;
}
}
HeaderNode.ChildNodes.Add(PNode);
}
TreeView1.Nodes.Add(HeaderNode);
if (Request.QueryString["catcod"] != null)
{
ENode(Request.QueryString["catcod"]);
}
TreeView1.DataBind();
}
public void ENode(String catcod)
{
TreeNode t = new TreeNode();
for (Int32 i = 0; i < TreeView1.Nodes.Count; i++)
{
TreeNode nd = TreeView1.Nodes[i];
for (Int32 j = 0; j < nd.ChildNodes.Count;j++)
{
if (TreeView1.Nodes[0].ChildNodes[j].Expanded==true)
{
TreeView1.Nodes[0].ChildNodes[j].Collapse();
}
t = TreeView1.Nodes[0].ChildNodes[j];
if (t.Value == catcod)
{
t.Expand();
}
}
}
}
public Int32 CountBooks(Int32 catdetcod)
{
var totalbooks = (from objbooks in obj.tbbooks
join objcatdet in obj.tbcatdets on objbooks.bookcatdetcod equals objcatdet.catdetcod
where objcatdet.catdetcod == catdetcod
select objbooks.bookcod).Count();
return totalbooks;
}
}
----------
谢谢,
[removedemailaddress]
----------
Thanks,
[removedemailaddress]
推荐答案
1.我的主页变得非常沉重.为什么?
1. My home page became very heavy. Why?
可能是您正在树视图中加载大量节点.另外,也请树视图节点限制 [
May be you are loading heavy number of nodes in treeview. Also check this one too Treeview node limit[^]
2.尚未应用缓存.我想在页面上应用缓存.问题是,页面上的每个内容都是动态的.我想我将不得不应用缓存的缓存依赖"类型.请告知我应该在哪里应用缓存以及应该实现哪种类型的缓存.
2. No Cacheing is applied yet. I want to apply cacheing on the page.. Problem is, every content on the page is Dynamic .I think I will have to apply Cache Dependency type of Cacheing. Please advice me Where should I apply cacheing and Which type of Cacheing I should implement.
Caching Dynamic Pages with ASP.NET[^]
3.如果我将DataSet放入缓存中,请提出建议,这将足以提高TreeView控件的性能.
3. If I put DataSet in cache Please advice will that be sufficient to increase the performance of TreeView controls.
一定. 如何缓存数据集以停止 [
Surely. How do I cache a dataset to stop round trips to db?[^]
4.如果需要使用SiteMap绑定TreeView控件,应如何动态地使用DataSet填充SiteMap?我的桌子有时会有信息变动..所以我希望它是动态的...
4. If I need to use SiteMap to bind TreeView control, How should I populate SiteMap with DataSet Dynamically? I have table having Information which chnages sometimes.. So I want it to be dynamic...
带有SiteMapDataSource的ASP.NET TreeView PopulateNodesFromClient [
ASP.NET TreeView PopulateNodesFromClient with SiteMapDataSource[^]
5.请告诉我应该为该页面申请的缓存类型.
5. Please advice me the types of Caching I should apply for this page.
ASP.NET 2.0中的缓存技术 [ TreeView ASP.NET随需填充 [!IsPostBack [
Caching Techniques in ASP.NET 2.0[^]
Attachments
Also you can use this one too, it will increase the performance
TreeView ASP.NET Populate OnDemand[^]
You may use !IsPostBack[^] in page load event but depends.
我在网页性能方面遇到问题.
I am having issue with Performance of webpage.
提高ASP.NET性能的50条提示 [ ^ ]
顺便说一句,您已经很好地问了您的问题(包括解释,代码,问题列表等),请始终保持继续.干杯. :thumbsup:
50 Tips to Boost ASP.NET Performance[^]
BTW you have asked your question very well(with explanation, code, list of issues, etc) keep continue always. Cheers. :thumbsup:
你好,
非常感谢您的回复...
我通过调试主页发现了什么.我用来填充页面主数据的DataList控件中有一个Image tage.如果禁用此"img"标签,则页面加载速度更快.
TreeView控件现在的性能更好.干杯Thatraja…为建议IsPostBack ..我只是想念它.
如何调试?
#好吧,我在母版页中添加了另一个内容页. (新页面控件是:母版页控件,仅此而已……内容页为空.).按F5….母版页的Treeview有效加载...并且没有引起任何问题.....对此我感到非常满意. :)
#现在,我在此内容页面上拖了一个WUC [数据列表+嵌套的WUC(网格视图)].然后按F5 ..页面开始缓慢加载..我在此WUC中发现了一个问题.
下一步..
#我添加了一个普通的Web窗体....我将此WUC放置在此Webform上..按F5 ..此Webform仍在加载问题.....这里,我确认此DataList控件存在问题,而不是TreeView .. :)
这是我的DataList控件的代码:
Hello,
Thank you very much for your replies...
What I found by debugging my homepage that. The DataList control I use to populate the main data for my page have an Image tage in it. If I disable this "img" tag .. Page loaded and performance is faster.
TreeView Control is performing better now. Cheers Thatraja… for suggesting IsPostBack.. I had just missed it.
How I Debugged?
# Well, I added another content page in the Master Page. (New page controls are: controls of Master page, that’s it…content page is empty).. Pressed F5…. Treeview of Master page loaded efficiently... and causing no problem..... I am very happy with this. :)
# Now, I Dragged a WUC [ Datalist + nested WUC (Gridview)] on this content page..and Pressed F5.. page stared loading slowly.. I found a problem in this WUC.
Next..
# I added a normal Web Form....I placed this WUC onto this webform.. Pressed F5.. Still loading problem in this webform .....Here, I confirmed that there is a problem in this DataList control not TreeView.. :)
Here is code of my DataList Control:
<asp:DataList ID="DataList1" runat="server" CellPadding="0"
DataKeyField="bookcod" GridLines="Horizontal" HorizontalAlign="Center"
onitemcommand="DataList1_ItemCommand" RepeatColumns="3" Width="100%">
<ItemTemplate>
<table>
<tr>
<td>
<%--<img src='<%#Eval("bookimg") %>' width="65" height="89" alt="Book Cover" align="left" />--%>
Title: <asp:Label ID="Label1" runat="server"
Text='<%#Eval("booktit") %>'></asp:Label>
<br />
Author: <asp:Label ID="Label2" runat="server" Text='<%#Eval("autnam") %>'></asp:Label>
<br />
Publisher: <asp:Label ID="Label3" runat="server" Text='<%#Eval("pubnam") %>'></asp:Label>
<br />
Price:
<asp:Label ID="Label4" runat="server" Text='<%#Eval("bookprc") %>'></asp:Label>
<br />
</td>
</tr>
<tr>
<td align="left" valign="top">
<asp:ImageButton ID="ImageButton1" runat="server"
CommandArgument='<%#Eval("bookcod") %>' Height="20" ImageAlign="Top"
ImageUrl="~/images/addtocart3.gif" Width="90" />
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
=======
如果我评论"img"标签.....按F5键....有效地加载页面..那就是我想要的主页…(仍然没有缓存实现.. :)这意味着在应用缓存技术之后,它会更多更快.. :) :))
所以..
< b>问题是:</b>
1.应该为DataList控件使用哪种类型的图像(.gif,.jpeg,.png等),以实现更快的加载速度和更好的质量?这是一个在线图书销售网站.它将有书的图片...和一些按钮图片...仅
2.我将图像存储在主目录中.并且只需将图像的唯一名称保存在我的数据库(SQL Server 2008)中以进行检索过程(我认为是其正常过程).
就我而言,只有管理员上载图像,而不是客户端/用户.请问在我的情况下处理图像的最佳方法是什么?
谢谢,
jaspal82ATgmailDOTcom
=======
If I comment the "img" tag…..Pressed F5.... Page loaded efficiently.. That’s what I want for my Homepage…(Still no caching implementation yet.. :) It means after applying caching techniques It will be more faster.. :) :) )
So..
<b>The issues are:</b>
1. Which type of image (.gif, .jpeg, .png etc) I should use for DataList control for faster loading and bit better quality? This is an online book selling website. It will have pictures of books... and few buttons pictures...only
2. I am storing images on the main directory. And just saving the unique name of image in my database (sql server 2008) for retrieval process (Its normal process I reckon).
In my case, only Admin uploads the images, not the client/user. What is the best approach in dealing with storing images in my case please?
Thanks,
jaspal82ATgmailDOTcom
这篇关于TreeView效率问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!