峻
峻祁连
Unregistered / Unconfirmed
GUEST, unregistred user!
下面是实现Microsoft IEWebControl TreeView的级联Check的c#代码,运行效果挺好的,我把它贴出来供大家参考。但是有个缺点,由于要求autopostback所有刷新太厉害了,谁能改写成javascript的客户端代码?
/// <summary>
/// Recursively set child nodes values (递归的设置子节点的值)
/// </summary>
/// <param name="Item">the current node</param>
/// <param name="Value">the value to change the node to</param>
private void ChangeChildNodeValues(Microsoft.Web.UI.WebControls.TreeNode Item, bool Value)
{
if(Item.Nodes.Count == 0)
Item.Checked = Value;
else
{
// iterate through the children and set their values
for(int intCurrentChild = 0;intCurrentChild < Item.Nodes.Count;
intCurrentChild++)
ChangeChildNodeValues(Item.Nodes[intCurrentChild], Value);
// set the current node's value
Item.Checked = Value;
}
}
/// <summary>
/// 改变选中节点的父节点的值
/// </summary>
/// <param name="Item">选中的节点</param>
/// <param name="Value">要给checkBox赋的值</param>
private void ChangeParentNodeValues(Microsoft.Web.UI.WebControls.TreeNode Item, bool Value)
{
object tnParent = Item.Parent;
while(tnParent != null)
{
switch(tnParent.GetType().ToString())
{
case "Microsoft.Web.UI.WebControls.TreeNode":
((Microsoft.Web.UI.WebControls.TreeNode)tnParent).Checked = Value;
tnParent = ((Microsoft.Web.UI.WebControls.TreeNode)tnParent).Parent;
break;
case "Microsoft.Web.UI.WebControls.TreeView":
tnParent = null;
break;
}
}
}
/// <summary>
/// Recursively set child nodes values (递归的设置子节点的值)
/// </summary>
/// <param name="Item">the current node</param>
/// <param name="Value">the value to change the node to</param>
private void ChangeChildNodeValues(Microsoft.Web.UI.WebControls.TreeNode Item, bool Value)
{
if(Item.Nodes.Count == 0)
Item.Checked = Value;
else
{
// iterate through the children and set their values
for(int intCurrentChild = 0;intCurrentChild < Item.Nodes.Count;
intCurrentChild++)
ChangeChildNodeValues(Item.Nodes[intCurrentChild], Value);
// set the current node's value
Item.Checked = Value;
}
}
/// <summary>
/// 改变选中节点的父节点的值
/// </summary>
/// <param name="Item">选中的节点</param>
/// <param name="Value">要给checkBox赋的值</param>
private void ChangeParentNodeValues(Microsoft.Web.UI.WebControls.TreeNode Item, bool Value)
{
object tnParent = Item.Parent;
while(tnParent != null)
{
switch(tnParent.GetType().ToString())
{
case "Microsoft.Web.UI.WebControls.TreeNode":
((Microsoft.Web.UI.WebControls.TreeNode)tnParent).Checked = Value;
tnParent = ((Microsoft.Web.UI.WebControls.TreeNode)tnParent).Parent;
break;
case "Microsoft.Web.UI.WebControls.TreeView":
tnParent = null;
break;
}
}
}