我在页面中实现了telerik Tree-view并使用web-service填充节点。 源代码看起来像
<telerik:RadTreeView ID="tvNodes" runat="server" EnableDragAndDrop="false" ExpandAnimation-Type="OutExpo" ExpandAnimation-Duration="800" EnableDragAndDropBetweenNodes="false" CollapseAnimation-Type="OutElastic" CollapseAnimation-Duration="800" Skin="Windows7" OnNodeDrop="tvNodes_HandleDrop" ClientNodePopulating="nodePopulating">
<ContextMenus>
<telerik:RadTreeViewContextMenu ID="NodesTreeMenu" runat="server" CssClass="MenuGroup" Skin="Windows7">
<CollapseAnimation Type="none" />
</telerik:RadTreeViewContextMenu>
</ContextMenus>
<WebServiceSettings Path="../ManageNode.asmx" Method="GetNodes">
</WebServiceSettings>
</telerik:RadTreeView>
的Javascript
function nodePopulating(sender, eventArgs) {
var node = eventArgs.get_node();
var context = eventArgs.get_context();
SelectedType = '1'//selected node id.
SearchText = ''
context["ParentID"] = node.get_value();
context["AllowDragAndDrop"] = allowDragDrop;
context["SelectedType"] = SelectedType;
context["SearchText"] = SearchText;
}
的webmethod
[WebMethod]
public RadTreeNodeData[] GetNodes(RadTreeNodeData node, object context)
{
IDictionary<string, object> contextDictionary = (IDictionary<string, object>)context;
List<RadTreeNodeData> nodes = new List<RadTreeNodeData>();
int parentID = Convert.ToInt32(contextDictionary["ParentID"]);
bool AllowDragAndDrop = Convert.ToBoolean(contextDictionary["AllowDragAndDrop"]);
int selectedType = Convert.ToInt32(contextDictionary["SelectedType"]);
string SearchText = Convert.ToString(contextDictionary["SearchText"]);
dsNodes = NodeBLL.GetAllRecordsByNodeDefinition(selectedType, parentID, SearchText.Trim());
for (int rowCount = 0; rowCount < dsNodes.Tables[0].Rows.Count; rowCount++)
{
DataRow childRow = dsNodes.Tables[0].Rows[rowCount];
RadTreeNodeData childNode = new RadTreeNodeData();
if (Convert.ToInt16(childRow["StatusID"]) == Convert.ToInt16(Common.NodeStatus.Archieve))
{
childNode.Text = Common.DecodeXML(Convert.ToString(childRow["Name"])) + Common.deleteFlag;
}
else
{
childNode.Text = Common.DecodeXML(Convert.ToString(childRow["Name"]));
}
childNode.Value = Convert.ToString(childRow["ID"]);
childNode.Attributes.Add(Common.virtualIDAtt, Convert.ToString(childRow["virtualID"]));
childNode.Attributes.Add(Common.isVirtualExist, Convert.ToString(childRow["isVirtualExist"]));
childNode.Attributes.Add(Common.NodeDefinitionID, Convert.ToString(childRow["NodeDefinitionID"]));
childNode.Attributes.Add(Common.ParentNodeID, Convert.ToString(childRow["ParentID"]));
childNode.Attributes.Add(Common.Position, Convert.ToString(childRow["Position"]));
childNode.Attributes.Add(Common.NodeDefinition, Convert.ToString(childRow["NodeDefinition"]));
childNode.ExpandMode = (Convert.ToInt32(childRow["ischildexists"]) > 0) ? TreeNodeExpandMode.WebService : TreeNodeExpandMode.ClientSide;
nodes.Add(childNode);
}
return nodes.ToArray();
}
当我点击展开箭头然后通过javascript函数调用web方法来填充子节点时,它工作得很完美,当父节点有1000多个子节点时我在性能上有问题,我想在批处理模式下实现,就像用户一样单击展开箭头,然后使用更多按钮加载200子节点,然后单击更多按钮,然后加载下一个200节点。任何人都有想法实现这个功能。
谢谢, Mohmedsadiq。