asp.net1.1下权限配置系统从设计到实现(三)
来源:互联网 发布:小榄淘宝美工培训学校 编辑:程序博客网 时间:2024/06/03 02:07
怎么用脚本实现TreeView的父子节点联动功能? 由于Firefox本身的特点,在实现时分别在IE下用脚本实现,在Firefox下用.cs代码实现。由于这两种浏览器兼容性实在不怎么好,艾!
OK,废话少说,现在首先给出实现TreeView父子节点联动选种的脚本方法:
OK,废话少说,现在首先给出实现TreeView父子节点联动选种的脚本方法:
function ChcekFuncNodes(e)
{
var i=e.clickedNodeIndex;
var node=e.getTreeNode(i);
var NodeArray=node.getChildren();
if(NodeArray.length>0)
{
if(node.getAttribute("Checked") == true)
{
for(var i=0;i<NodeArray.length;i++)
{
CheckTreeNode(NodeArray[i],true,false);
GetSelectedFunctionPointID(NodeArray[i]);
}
GetSelectedFunctionID(node);
}
else
{
for(var i=0;i<NodeArray.length;i++)
{
CheckTreeNode(NodeArray[i],false,false);
}
}
}
else
{
var ParentNode=node.getParent();
if(ParentNode!=null)
{
if(node.getAttribute("Checked") == true)
{
GetSelectedFunctionPointID(node);
CheckTreeNode(ParentNode,true,false);
GetSelectedFunctionID(ParentNode);
}
else
{
if(AllChildTreeNodeSameCheck(ParentNode,false))
{
CheckTreeNode(ParentNode,false,false);
}
}
}
else
{
CheckTreeNode(node,true,false);
GetSelectedFunctionID(node);
}
}
}
{
var i=e.clickedNodeIndex;
var node=e.getTreeNode(i);
var NodeArray=node.getChildren();
if(NodeArray.length>0)
{
if(node.getAttribute("Checked") == true)
{
for(var i=0;i<NodeArray.length;i++)
{
CheckTreeNode(NodeArray[i],true,false);
GetSelectedFunctionPointID(NodeArray[i]);
}
GetSelectedFunctionID(node);
}
else
{
for(var i=0;i<NodeArray.length;i++)
{
CheckTreeNode(NodeArray[i],false,false);
}
}
}
else
{
var ParentNode=node.getParent();
if(ParentNode!=null)
{
if(node.getAttribute("Checked") == true)
{
GetSelectedFunctionPointID(node);
CheckTreeNode(ParentNode,true,false);
GetSelectedFunctionID(ParentNode);
}
else
{
if(AllChildTreeNodeSameCheck(ParentNode,false))
{
CheckTreeNode(ParentNode,false,false);
}
}
}
else
{
CheckTreeNode(node,true,false);
GetSelectedFunctionID(node);
}
}
}
function CheckTreeNode(chilNode,isCheck,atuoSetChilTreeNode)
{
if(chilNode!=null)
{
//alert(chilNode);
chilNode.setAttribute('checked',isCheck);
if(atuoSetChilTreeNode)
{
CheckChildTreeNode(chilNode,isCheck)
}
}
}
{
if(chilNode!=null)
{
//alert(chilNode);
chilNode.setAttribute('checked',isCheck);
if(atuoSetChilTreeNode)
{
CheckChildTreeNode(chilNode,isCheck)
}
}
}
function CheckChildTreeNode(Pnode,isCheck)
{
if(Pnode!=null)
{
var arr=Pnode.getChildren();
for(var i=0;i<arr.length;i++)
{
arr[i].setAttribute('checked',isCheck);
}
}
}
{
if(Pnode!=null)
{
var arr=Pnode.getChildren();
for(var i=0;i<arr.length;i++)
{
arr[i].setAttribute('checked',isCheck);
}
}
}
function AllChildTreeNodeSameCheck(PareNode, value)
{
if(PareNode!=null)
{
var chids=PareNode.getChildren();
for(var i=0;i<chids.length;i++)
{
if(chids[i].getAttribute("Checked")!=value)
{
return false;
}
}
}
return true;
}
大家都知道,不用多讲,下面两个方法是纪录用户选中的FunctionID和FunctionPointID,通过隐藏控件传递给.cs文件使用,补充一下就是为什么我用document.getElementById('<%=hidenFunID.ClientID%>')而不用document.getElementById('hidenFunID')?原因是我的脚本是放在ascx文件中的(即UserControl中的)所以只能通过这种方式来找控件,否则就找不到哟!算是个小技巧吧 :){
if(PareNode!=null)
{
var chids=PareNode.getChildren();
for(var i=0;i<chids.length;i++)
{
if(chids[i].getAttribute("Checked")!=value)
{
return false;
}
}
}
return true;
}
function GetSelectedFunctionID(nodes)
{
var hideFun = document.getElementById('<%=hidenFunID.ClientID%>');
var checkFun = hideFun.value;
checkFun += nodes.getAttribute("ID")+";";
hideFun.value =checkFun;
// alert(hideFun.value);
}
{
var hideFun = document.getElementById('<%=hidenFunID.ClientID%>');
var checkFun = hideFun.value;
checkFun += nodes.getAttribute("ID")+";";
hideFun.value =checkFun;
// alert(hideFun.value);
}
function GetSelectedFunctionPointID(nodes)
{
var hideFunPoint = document.getElementById('<%=txtPointId.ClientID%>');
var checkFun = hideFunPoint.value;
checkFun += nodes.getAttribute("ID")+";";
hideFunPoint.value =checkFun;
//alert(hideFunPoint.value);
}
最后一步,让TreeView父子节点联动产生真正的效果,哈哈.................{
var hideFunPoint = document.getElementById('<%=txtPointId.ClientID%>');
var checkFun = hideFunPoint.value;
checkFun += nodes.getAttribute("ID")+";";
hideFunPoint.value =checkFun;
//alert(hideFunPoint.value);
}
private void Page_Load(object sender, System.EventArgs e)
{
if(!Page.IsPostBack )
{
tvRoleFunctions.Attributes.Add("oncheck","ChcekFuncNodes(this)");
}
}
{
if(!Page.IsPostBack )
{
tvRoleFunctions.Attributes.Add("oncheck","ChcekFuncNodes(this)");
}
}
下次写作预告:
怎么实现Select All TreeView全部节点的功能?怎么实现展开和折叠自如?
http://jigee.cnblogs.com/archive/2006/06/09/421367.html#421589
- asp.net1.1下权限配置系统从设计到实现(三)
- asp.net1.1下权限配置系统从设计到实现(一)
- asp.net1.1下权限配置系统从设计到实现(二)
- asp.net1.1下权限配置系统从设计到实现(四)
- 将ASP.NET1.0升级到ASP.NET1.1
- 从ASP.NET1.1升级到ASP.NET2.0需要考虑的Cookie问题
- 从ASP.NET1.1升级到ASP.NET2.0要考虑的Cookie问题
- asp.net1.1部署到Win2000发生诡异的问题
- 从Mysql到系统权限
- ASP.NET1.1下TreeView海量数据绑定
- ASP.NET1.1下TreeView海量数据绑定
- ASP.NET1.1下TreeView海量数据绑定
- asp.net1.1/2.0中快速实现单点登陆
- asp.net1.1/2.0中快速实现单点登陆
- Asp.net1.1实现仿2.0 MasterPage效果
- asp.net1.1中DataList如何实现分页
- 记帐系统从需求到实现 ----数据库的设计
- (转贴)将asp.net1.1的应用程序升级到asp.net2.0的一点心得
- 侵入远程的代码也写好了
- 在ASP.net中保存/取出图片入/从SQL数据库(可用于上传图片)
- asp.net1.1下权限配置系统从设计到实现(一)
- asp.net1.1下权限配置系统从设计到实现(二)
- 在Suse10.1下编译内核+安装perfctr
- asp.net1.1下权限配置系统从设计到实现(三)
- 博股
- C++中关于输出流重定向到文件
- 结构体中数据的对齐性
- 夜凉如水
- 开始使用lua5.1
- 大学生一定要理解的事
- 祝福妹妹考试顺利-高考的最后一天
- 并非万能的XML