.net1.1下使用树控件,如何实现选择了父节点的CheckBox,其子节点的CheckBox均被选中!!
如题,.net1.1下的iewebcontrol控件, 似乎没有和CheckBox绑定的事件,我该怎么实现上面的功能呢?
------解决方案--------------------private void TreeView1_Check(object sender, Microsoft.Web.UI.WebControls.TreeViewClickEventArgs e)
{
Microsoft.Web.UI.WebControls.TreeNode node=TreeView1.GetNodeFromIndex(TreeView1.SelectedNodeIndex.ToString());
//connE.Alert(node.NodeData.ToString(),Page);
SetAllNodeData(node.Nodes);
}
private void SetAllNodeData(TreeNodeCollection tnc)
{
foreach(TreeNode node in tnc)
{
if(node.Nodes.Count!=0)
{
SetAllNodeData(node.Nodes);
}
if (node.Checked)
{
node.Checked = false;
}
else
{
node.Checked = true;
}
}
}
这个是测试过的,选定某一节点后,进行checke的时候,所有子节点都将选择(或取消)
不过这是服务器端的.AutoPostBack= "True "有些麻烦(先选定然后再check)
客户端做就好了...
------解决方案--------------------用JS,参考如下:
http://blog.csdn.net/Eray/archive/2007/04/23/1575302.aspx
------解决方案--------------------http://hi.baidu.com/erics_lele/blog/item/abe751a917fc89fe1f17a21b.html
------解决方案--------------------function getTargetElement(evt) {
var elem
if (evt.target)
{
elem = (evt.target.nodeType == 3) ? evt.target.parentNode : evt.target
}
else
{
elem = evt.srcElement
}
return elem
}
function OnClientTreeNodeChecked(evt)
{
evt = (evt) ? evt : ((window.event) ? window.event : " ");
if(evt == " ")
{
return;
}
var obj = getTargetElement(evt);
var hasTreeNode = false;
if(obj.tagName)
{
if (obj.tagName == "INPUT " && obj.type == "checkbox ") {
var treeNode = obj;
while (obj.tagName != "TABLE ")
{
obj = obj.parentNode;
}
var parentTreeDeep = obj.rows[0].cells.length;
var parentTreeNode = obj.rows[0].cells[0];
var oDiv = obj.parentNode;
if( null == oDiv )
{
return;
}
if( 1 != oDiv.nodeType)
{
return;
}
var tables = oDiv.getElementsByTagName( "TABLE ");
if( null == tables)
{
return;
}
var tableCount = tables.length;
if(tableCount < 1)
{
return;
}
for (i = 0; i < tableCount; i++)
{
if ( obj == tables[i] )
{
hasTreeNode = true;
i++;
if (tableCount == i )
{
return;
}
}
if (hasTreeNode)
{
var childTreeDeep = tables[i].rows[0].cells.length;
if (childTreeDeep > parentTreeDeep)
{
var cellTreeNode = tables[i].rows[0].cells[childTreeDeep - 1];
var inputs = cellTreeNode.getElementsByTagName( "INPUT ");
if( null != inputs)
{
inputs[0].checked = treeNode.checked;
}
}
else
{