2014-05-25 17 views
0

我对Telerik的RadTreeList控件有问题。当我将数据加载到RadTreeList时,只有当我单击展开按钮时,才可以访问其子项。没有扩大,ChildItems列表是空的。有没有办法让一个特定的父母的孩子没有扩大?RadTreeList ChildItems列表为空

+0

平台ASP .NET – SteppingRazor

回答

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(); 
    } 
}