我使用XMLDataSource將XML數據綁定到treeview。它的工作方式,但是當節點和子節點的數量增加時,treenode擴展並顯示iframe需要較長時間的 中的內容。如何減少在asp.net中填充樹節點所花費的時間c#treeview?
<asp:TreeView ID="TreeView1" OnSelectedNodeChanged = "OnClick" runat="server"
ExpandDepth="0" ShowExpandCollapse="true" ForeColor="Red" Font-Underline = "false"
ondatabinding="TreeView1_DataBinding" CollapseImageUrl = "Resources/TocColapse.bmp" ExpandImageUrl = "Resources/TocParent.bmp" Font-Names="Arial" >
<SelectedNodeStyle Font-Underline="false" BackColor="White" ForeColor="#0483e0" />
<NodeStyle Font-Size="11pt" ForeColor="white" HorizontalPadding="5px"
NodeSpacing="0px" VerticalPadding="0px" Font-Underline = "false" />
<ParentNodeStyle ForeColor="#0483e0" Font-Underline = "false" />
<LeafNodeStyle ForeColor="#0483e0" Font-Underline = "false" ImageUrl = "Resources/TocChild.bmp" />
</asp:TreeView>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" XPath="/*/*" EnableCaching = "false" ></asp:XmlDataSource>
在樹狀的OnDataBinding事件中,我採取了以下代碼:
TreeNodeBinding[] TreeNode = new TreeNodeBinding[Count];
for (int i = 0; i < Count; i++)
{
TreeNode[i] = new TreeNodeBinding();
TreeNode[i].DataMember = TableOfContents[i].GetElementName();
TreeNode[i].TextField = TableOfContents[i].GetFirstAttributeName();
TreeNode[i].ValueField = TableOfContents[i].GetSecondAttributeName();
// TreeNode[i].Target = "contentFrame";
TreeView1.DataBindings.Add(TreeNode[i]);
}
。有沒有可能使用XMLDatasource? – Mahantesh 2010-12-15 12:43:49
http://www.codegod.de/WebAppCodeGod/TreeView-ASP-NET-Populate-OnDemand-AID409.aspx – Cromathaar 2010-12-15 13:16:40
我閱讀本教程,因爲我修改了我的代碼..但它不會觸發OntreeItempopulate方法...你會根據懶惰綁定來修改我的代碼嗎? – Mahantesh 2010-12-15 13:22:28