{ //?添加当前节点的子节点
Node.Text = Row["ConText"].ToString();
Node.Value = Row["id"].ToString();
pNode.ChildNodes.Add(Node);
Node.Expanded = true;
pNode.ChildNodes[0].Selected = true; //选中根节点的第一个子节点
TextBox1.Text = pNode.ChildNodes[0].Value;
TextBox2.Text = pNode.ChildNodes[0].Text;
AddTree(Int32.Parse(Row["ID"].ToString()), Node); //再次递归
}
如果根节点的第一个子节点下面还有子节点,那默认这个子节点被选上,这不是我要的效果
我要的是根节点的第一个子节点被选上
------解决方案--------------------------------------------------------
node.Parent.ChildNodes[0]
------解决方案--------------------------------------------------------
try
- JScript code
<script language="javascript" type="text/javascript"> function client_OnTreeNodeChecked() { var obj = window.event.srcElement; var treeNodeFound = false; var checkedState; if (obj.tagName == "INPUT" && obj.type == "checkbox") { var treeNode = obj; checkedState = treeNode.checked; do { obj = obj.parentElement; } while (obj.tagName != "TABLE") var parentTreeLevel = obj.rows[0].cells.length; var parentTreeNode = obj.rows[0].cells[0]; var tables = obj.parentElement.getElementsByTagName("TABLE"); var numTables = tables.length if (numTables >= 1) { for (i=0; i < numTables; i++) { if (tables[i] == obj) { treeNodeFound = true; i++; if (i == numTables) { return; } } if (treeNodeFound == true) { var childTreeLevel = tables[i].rows[0].cells.length; if (childTreeLevel > parentTreeLevel) { var cell = tables[i].rows[0].cells[childTreeLevel - 1]; var inputs = cell.getElementsByTagName("INPUT"); inputs[0].checked = checkedState; } else { return; } } } } } } </script>
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
------解决方案--------------------------------------------------------
TreeView1.Nodes[0].Expand();
TreeView1.Nodes.Selected .clear();
TreeView1.Nodes[0].ChildNodes[0].Selected = true;