这里一定有我遗漏的东西。我有两个 RadTreeView 实例,为此我将节点检查数据存储在 cookie 中。页面加载后,我想读取这个 cookie,并相应地设置检查状态。
所以我有这个 OnDataBound 事件:
protected void RadTreeView1_OnDataBound(object sender, EventArgs e)
{
HttpCookie checkedCookie = Request.Cookies[DataType + "Checked"];
if (checkedCookie != null)
{
var cookieValue = checkedCookie.Values["Checked"];
if (cookieValue != null)
{
var checkedNodeValues = cookieValue.Split('*');
foreach (string nodeValue in checkedNodeValues)
{
RadTreeNode checkedNode = RadTreeView1.FindNodeByValue(HttpUtility.UrlDecode(nodeValue));
if (checkedNode != null)
checkedNode.Checked = true;
}
}
}
}
在 foreach 循环中,我为每个 cookie 值找到一个对应的节点。更重要的是,它们的初始 Checked 状态为 false。
那么为什么还要检查所有其他节点呢?