下面的3个季度,每个季度下的日都被check。uncheck时同样。
在expand一个以上的月节点时,expand和collapse正常,但是checkbox显示状态出错。例如,1月节点checked属性为ture,但是checkbox居然
没有勾。此时,checked属性值是正确的,但checkbox与TreeNode.checked不同步。
函数treeGen()用于生成树,在tree1.aspx.cs中,工作正常。我在tree1.aspx中写了两个javascript函数(checkNodeClient1(tnTreeNode)递
归实现,checkNodeClient(tnTreeNode)循环实现,用于控制checked属性),在tree1.aspx.cs中写了一个c#函数(checkNodeServer(TreeNode
treeNode)递归实现,用于控制checked属性),但都遇到了同样的bug。
代码如下,请问如何解决?
1.code in tree1.aspx
<code in tree1.aspx>
<script language="javascript">
//check/uncheck all the children, in term of the current node's state
function checkNodeClient1(tnTreeNode)
{
var arrCheckedTreeNode = tnTreeNode.getChildren();
var b = tnTreeNode.getAttribute("CHECKED");
for (var i = 0; i < arrCheckedTreeNode.length; i++)
{
arrCheckedTreeNode[i].setAttribute("CHECKED",b);
checkNodeClient(arrCheckedTreeNode[i]);
window.setTimeout('',1000);
}
}
//check/uncheck all the children, in term of the current node's state
function checkNodeClient(treeNode)
{
var i,j,k,l,b;
var arrSeason,arrMonth,arrTendays,arrDay;
var sub3 = treeNode.getAttribute("NodeData").substr(0,3);
//if the first three characters of the current node are yea,it is year
if (sub3 == "yea")
{
arrSeason = treeNode.getChildren();
b = treeNode.getAttribute("CHECKED");
//traverse season
for (i = 0; i < arrSeason.length; i++)
{
arrSeason[i].setAttribute("CHECKED",b);
arrMonth = arrSeason[i].getChildren();
//traverse month
for (j = 0; j < arrMonth.length; j++)
{
arrMonth[j].setAttribute("CHECKED",b);
arrTendays = arrMonth[j].getChildren();
//traverse tendays
for (k = 0; k < arrTendays.length; k++)
{
arrTendays[k].setAttribute("CHECKED",b);
arrDay = arrTendays[k].getChildren();
//traverse day
for (l = 0; l < arrDay.length; l++)
{
arrDay[l].setAttribute("CHECKED",b);
}
}
}
}
}//year
//if the first three characters of the current node are sea,it is season
else if (sub3 == "sea")
{
arrMonth = treeNode.getChildren();
b = treeNode.getAttribute("CHECKED");
//traverse month
for (j = 0; j < arrMonth.length; j++)
{
arrMonth[j].setAttribute("CHECKED",b);
arrTendays = arrMonth[j].getChildren();
//traverse tendays
for (k = 0; k < arrTendays.length; k++)
{
arrTendays[k].setAttribute("CHECKED",b);
arrDay = arrTendays[k].getChildren();
//traverse day
for (l = 0; l < arrDay.length; l++)
{
arrDay[l].setAttribute("CHECKED",b);
}
}
}
}//season
//if the first three characters of the current node are mon,it is month
else if (sub3 == "mon")
{
arrTendays = treeNode.getChildren();
b = treeNode.getAttribute("CHECKED");
//traverse tendays
for (k = 0; k < arrTendays.length; k++)
{
arrTendays[k].setAttribute("CHECKED",b);
arrDay = arrTendays[k].getChildren();
//traverse day
for (l = 0; l < arrDay.length; l++)
{
arrDay[l].setAttribute("CHECKED",b);
}
}
}//month
//if the first three characters of the current node are ten,it is tendays
else if (sub3 == "ten")
{
arrDay = treeNode.getChildren();
b = treeNode.getAttribute("CHECKED");
//traverse day
for (l = 0; l < arrDay.length; l++)
{
arrDay[l].setAttribute("CHECKED",b);
}
}//tendays
}
</script>
<script language="javascript" event="oncheck" for="Treeview1">
var tnCheckedNode = Treeview1.getTreeNode(Treeview1.clickedNodeIndex);
//alert(tnCheckedNode.getAttribute("TEXT"));
checkNodeClient(tnCheckedNode);
</script>
</code in tree1.aspx>
2.code in tree1.aspx.cs
<code in tree1.aspx.cs>
//generate the tree in Treeview1
private void treeGen()
{
//year
TreeNode tnYear = new TreeNode();
tnYear.Text = "1900";
tnYear.CheckBox = true;
tnYear.NodeData = "year1900";
Treeview1.Nodes.Add(tnYear);
for(int i = 1; i <= 4; i++)
{
//season
TreeNode tnSeason = new TreeNode();
tnSeason.Text = i + "season";
tnSeason.NodeData = "season" + i;
tnSeason.CheckBox = true;
tnYear.Nodes.Add(tnSeason);
//month
for(int j = 1; j <= 3; j++)
{
TreeNode tnMonth = new TreeNode();
tnMonth.Text = ((i-1) * 3 + j) + "month";
tnMonth.NodeData = "month" + j;
tnMonth.CheckBox = true;
tnSeason.Nodes.Add(tnMonth);
//tendays
for(int k = 1; k <= 3; k++)
{
TreeNode tnTendays = new TreeNode();
switch(k)
{
case 1:
tnTendays.Text = "firstTendays";
tnTendays.NodeData = "tendaysFirst";
break;
case 2:
tnTendays.Text = "middleTendays";
tnTendays.NodeData = "tendaysMiddle";
break;
case 3:
tnTendays.Text = "lastTendays";
tnTendays.NodeData = "tendaysLast";
break;
}
tnTendays.CheckBox = true;
tnMonth.Nodes.Add(tnTendays);
//day
for(int l = 1; l <= 10; l++)
{
TreeNode tnDay = new TreeNode();
//month: 1,3,5,7,8,10,12; last tendays; last two days
if(k == 3 && (((i-1) * 3 + j) == 1 || ((i-1) * 3 + j) == 3 || ((i-1) * 3 + j) == 5 ||
((i-1) * 3 + j) == 7 || ((i-1) * 3 + j) == 8 || ((i-1) * 3 + j) == 10 || ((i-1) * 3 + j) == 12) && l == 10)
{
tnDay = new TreeNode();
tnDay.Text = 30 + "day";
tnDay.NodeData = "day30";
tnDay.CheckBox = true;
tnTendays.Nodes.Add(tnDay);
tnDay = new TreeNode();
tnDay.Text = 31 + "day";
tnDay.NodeData = "day31";
tnDay.CheckBox = true;
tnTendays.Nodes.Add(tnDay);
break;
}
//others
else
{
int tnYearData = System.Convert.ToInt32(tnYear.NodeData.Substring(4,4));
//there are 29 days in February of a leap year
if(((i-1) * 3 + j) == 2 && k ==3 && (tnYearData % 100 != 0 && tnYearData % 4
== 0 || tnYearData % 400 == 0))
{
if(l == 10)
break;
}
//there are 28 days in February of a normal year
else if(((i-1) * 3 + j == 2) && k ==3)
{
if(l == 9)
break;
}
//others
tnDay.Text = ((k-1) * 10 + l) + "day";
tnDay.NodeData = "day" + ((k-1) * 10 + l);
tnDay.CheckBox = true;
tnTendays.Nodes.Add(tnDay);
}
}
}
}
}
}
//check/uncheck all the children, in term of the current node's state
private void checkNodeServer(TreeNode treeNode)
{
foreach(TreeNode tn in treeNode.Nodes)
{
tn.Checked = treeNode.Checked;
checkNodeServer(tn);
}
}
//check a checkbox
private void Treeview1_Check(object sender, Microsoft.Web.UI.WebControls.TreeViewClickEventArgs e)
{
mylabel.InnerText += "Checked (Node Index = " + e.Node.ToString() + ")";
checkNodeServer(Treeview1.GetNodeFromIndex(e.Node));
}
</code in tree1.aspx.cs>
14 个解决方案
#1
我也用过带checkbox的treeview,但没有出现你所说的问题。
#2
能具体说说吗?
#3
maybe your wrong!
#4
测试中......
#5
但愿是我的错,期待回应中……
#6
咋样了?
#7
help!
#8
用C#作是没有问题,用javascript我也有同样的问题,
http://expert.csdn.net/Expert/topic/2306/2306263.xml?temp=.4829981
http://expert.csdn.net/Expert/topic/2308/2308187.xml?temp=.3208734
http://expert.csdn.net/Expert/topic/2306/2306263.xml?temp=.4829981
http://expert.csdn.net/Expert/topic/2308/2308187.xml?temp=.3208734
#9
我也有同意的问题,在服务器中给 checked 设置值后,客户端checkbox的值就是不能与checked这个属性同步,我也正在调试,唉,但愿不是bug!
#10
http://expert.csdn.net/Expert/topic/1645/1645231.xml
#11
我试了一下,发现类似的问题
不过,我把“EnableViewState=False”就解决了
原因可能是,你用客户端对TreeView进行操作并不能影响“ViewState”
而用“getAttribute()”是从“ViewState”获取属性的
不过,我把“EnableViewState=False”就解决了
原因可能是,你用客户端对TreeView进行操作并不能影响“ViewState”
而用“getAttribute()”是从“ViewState”获取属性的
#12
[php]test[/php]
#13
<php>ft,不能解析</php>
#14
解决了
感谢各位!
具体方案如下:
看了TreeView的源码,属性应为"checked",必须完全匹配
在客户端可以完成上述功能,javascript可以避免闪烁,而且速度很快
top的代码完全正确
感谢各位!
具体方案如下:
看了TreeView的源码,属性应为"checked",必须完全匹配
在客户端可以完成上述功能,javascript可以避免闪烁,而且速度很快
top的代码完全正确
#1
我也用过带checkbox的treeview,但没有出现你所说的问题。
#2
能具体说说吗?
#3
maybe your wrong!
#4
测试中......
#5
但愿是我的错,期待回应中……
#6
咋样了?
#7
help!
#8
用C#作是没有问题,用javascript我也有同样的问题,
http://expert.csdn.net/Expert/topic/2306/2306263.xml?temp=.4829981
http://expert.csdn.net/Expert/topic/2308/2308187.xml?temp=.3208734
http://expert.csdn.net/Expert/topic/2306/2306263.xml?temp=.4829981
http://expert.csdn.net/Expert/topic/2308/2308187.xml?temp=.3208734
#9
我也有同意的问题,在服务器中给 checked 设置值后,客户端checkbox的值就是不能与checked这个属性同步,我也正在调试,唉,但愿不是bug!
#10
http://expert.csdn.net/Expert/topic/1645/1645231.xml
#11
我试了一下,发现类似的问题
不过,我把“EnableViewState=False”就解决了
原因可能是,你用客户端对TreeView进行操作并不能影响“ViewState”
而用“getAttribute()”是从“ViewState”获取属性的
不过,我把“EnableViewState=False”就解决了
原因可能是,你用客户端对TreeView进行操作并不能影响“ViewState”
而用“getAttribute()”是从“ViewState”获取属性的
#12
[php]test[/php]
#13
<php>ft,不能解析</php>
#14
解决了
感谢各位!
具体方案如下:
看了TreeView的源码,属性应为"checked",必须完全匹配
在客户端可以完成上述功能,javascript可以避免闪烁,而且速度很快
top的代码完全正确
感谢各位!
具体方案如下:
看了TreeView的源码,属性应为"checked",必须完全匹配
在客户端可以完成上述功能,javascript可以避免闪烁,而且速度很快
top的代码完全正确