用ASP.NET2.0的TreeView控件加载一个很大的XML文件时,一次性加载很慢,如何提高加载速度
------解决方案--------------------------------------------------------
介意 楼主 不要一次性 加载 所有的 数据
使用ajax树 来实现对应节点操作的 加载
http://www.xyhot.com/article.asp?id=116
http://blog.programfan.com/article.asp?id=23571
------解决方案--------------------------------------------------------
如何缓存
--------------------------
public DataTable GetCache_IndexByProductID(System.Web.UI.Page page, string productID)
{
string xmlpath = productID + ".xml ";//绝对地址
string cacheName = "CACHE_INDEX " + productID;
if(page.Cache[cacheName] == null)
{
DateTime absExpireTime = DateTime.Now.AddSeconds(EXPIRESTIME_INDEX); System.Web.Caching.CacheDependency dep = new System.Web.Caching.CacheDependency(new string[]{xmlpath});
page.Cache.Insert(cacheName, GetCatalogsToIndex(xmlpath, productID), dep, absExpireTime, TimeSpan.Zero); }
return page.Cache[cacheName] as DataTable;
}
也可以使用 System.Web.HttpRuntime.Cache[cachename] 或 System.Web.HttpContext.Cache[cachename]
------解决方案--------------------------------------------------------
<asp:TreeView ExpandDepth= "0 "
onclick= "javascript:return GoClick() " ID= "TreeView1 " runat= "server " PopulateNodesFromClient= "False " OnSelectedNodeChanged= "TreeView1_SelectedNodeChanged " OnTreeNodePopulate= "TreeView1_TreeNodePopulate ">
</asp:TreeView>
<script>
function GoClick()
{
var img = event.srcElement;
if(img.tagName.toLowerCase() == "img ")
{
var tb = img.parentNode.parentNode.parentNode.parentNode.parentNode;
var div = tb.nextSibling;
var a = div.firstChild.rows[0].cells[div.firstChild.rows[0].cells.length-1].firstChild
if(a.title == "-1 ")
{
event.srcElement.parentNode.parentNode.nextSibling.firstChild.click();
return false;
}
}
}
</script>