我对Telerik的RadTreeList
控件有疑问。当我将数据加载到RadTreeList
时,只有在单击“展开”按钮时才能访问其子项。如果不进行扩展,ChildItems
列表为空。有没有办法让特定父母的孩子不扩展?
答案 0 :(得分:0)
子项目仅在展开父项目时出现在控件中。但是,可以在代码中扩展项目以访问子项目。 (如果您不想将其展开,则可以将父级恢复到其折叠状态。)
由于控制生命周期中发生的事情,需要一点小心:
private bool isGetChildItems = false; protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { //if ( your condition that requires access to child items ) { isGetChildItems = true; //your logic to expand whichever nodes you need RadTreeList1.Items[0].Expanded = true; } } } protected void RadTreeList1_DataBound(object sender, EventArgs e) { //At this point in the lifecycle we can access the child items if (isGetChildItems) { //Do whatever it is we need to do with the child items ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "", string.Format("alert('Item 0 has {0} child items')", RadTreeList1.Items[0].ChildItems.Count), true); } } protected void RadTreeList1_PreRender(object sender, EventArgs e) { if (isGetChildItems) { //Restore node state, clear our flag and rebind isGetChildItems = false; RadTreeList1.Items[0].Expanded = false; RadTreeList1.DataBind(); } }