Problem reading values from custom treenode template's controls (works for subtrees but not for root tree)

1 posts, 0 answers
  1. Askar
    Askar avatar
    2 posts
    Member since:
    Jan 2013

    Posted 30 Jan 2013 Link to this post


    I use a RadTree with custom format of its elements. Namely, each element has also 3 radio buttons as RadioButtonList, defined in a custom template. The code used to create items of new radTree is:

    RadTreeNode node = new RadTreeNode(usedName + " [" + rs.ToString() + "]", "SECTION_" + rs.ToString()); // just some name and value
    node.NodeTemplate = new AdminFunctionsPhenoTreeTemplate(); // makes buttons
    node.ExpandMode = TreeNodeExpandMode.ServerSideCallBack;
    PhenoTree.Nodes.Add(node); // adding node to RadTree.
    // selections.
    RadioButtonList rbRights = (RadioButtonList)node.FindControl("rbRights");
    if (rbRights != null)
      setAccessLevelToRB(rbRights, accessLevel); // set correct radio button using rbRights.SelectedIndex

    This code successfully creates desired nodes and setAccessLeveltToRB indeed sets desired radio button as instructed.

    The very same code used to create sub-trees in server side callback - I use dynamic creation of subtrees after user wants to expand the tree. The only formal difference, it attaches new subtree to Nodes property of a parent node (as opposed to RadTree "PhenoTree" object here, of course). 

    When I receive a postback, I read the values of radio buttons like this:

    List<RadTreeNode> alls = (List<RadTreeNode>)PhenoTree.GetAllNodes();
                foreach (RadTreeNode node in alls)
                    RadioButtonList rbRights = (RadioButtonList)node.FindControl("rbRights");
                    accessLevel = getAccessLevelFromRB(rbRights); // this routine simply examines rbRights.SelectedIndex

     But buttons of primary root tree, created by the snippet above, always return default value, neither the one I inserted either in creation code (albeit it was reflected on screen) nor that I selected by mouse.


    class AdminFunctionsPhenoTreeTemplate : ITemplate
              public void InstantiateIn(Control container)
                  container.Controls.Add(new LiteralControl("<table style=\"margin:0px;padding:0px;\"><tr><td>"));
                  Label label1 = new Label();
                  label1.ID = "ItemLabel";
                  label1.Text = "Text";
                  label1.Font.Size = 8;
                  // label1.Font.Bold = true;
                  label1.DataBinding += new EventHandler(label1_DataBinding);
                  container.Controls.Add(new LiteralControl("</td><td>"));
                  RadioButtonList rbRights = new RadioButtonList();
                  rbRights.ID = "rbRights";
                  rbRights.Items.Add(new ListItem("r/o"));
                  rbRights.Items.Add(new ListItem("r/w"));
                  rbRights.Items.Add(new ListItem("r/w/meta"));
                  rbRights.SelectedIndex = 0;
                  rbRights.RepeatDirection = RepeatDirection.Horizontal;
                  container.Controls.Add(new LiteralControl("</td></tr></table>"));
              private void label1_DataBinding(object sender, EventArgs e)
                  Label target = (Label)sender;
                  RadTreeNode node = (RadTreeNode)target.BindingContainer;
                  string nodeText = (string)DataBinder.Eval(node, "Text");
                  target.Text = nodeText;

    I wonder what I am missing, please help me to make this work!
Back to Top