Hello,
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:
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:
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.
Template:
I wonder what I am missing, please help me to make this work!
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
}node.DataBind();
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.
Template:
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(label1);
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(rbRights);
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!