【问题标题】:RadTreeList ChildItems list is nullRadTreeList ChildItems 列表为空
【发布时间】:2014-05-25 15:10:47
【问题描述】:

我对 Telerik 的 RadTreeList 控件有疑问。当我将数据加载到RadTreeList 时,只有单击展开按钮才能访问其子项。不展开,ChildItems 列表为空。有没有办法在不扩展的情况下获得特定父母的孩子?

【问题讨论】:

    标签: c# asp.net .net telerik radtreelist


    【解决方案1】:

    子项仅在父项展开时出现在控件中。但是,可以在代码中扩展项目以访问子项目。 (如果您不希望它显示为展开状态,您可以将父级恢复到其折叠状态。)

    由于在控件的生命周期中什么时候发生,所以需要小心一点:

    私人布尔 isGetChildItems = false; protected void Page_Load(object sender, EventArgs e) { if (IsPostBack) { //if(您需要访问子项的条件) { isGetChildItems = true; //你的逻辑来扩展你需要的任何节点 RadTreeList1.Items[0].Expanded = true; } } } protected void RadTreeList1_DataBound(object sender, EventArgs e) { //在生命周期的这一点上,我们可以访问子项 if (isGetChildItems) { //对子项做任何我们需要做的事情 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(对象发送者,EventArgs e) { if (isGetChildItems) { //恢复节点状态,清除我们的标志并重新绑定 isGetChildItems = 假; RadTreeList1.Items[0].Expanded = false; RadTreeList1.DataBind(); } }

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-24
      • 1970-01-01
      • 2020-07-20
      • 2021-09-20
      相关资源
      最近更新 更多