日期:2014-05-19  浏览次数:20574 次

TreeView赋值NavigateUrl,如何触发SelectedNodeChanged 事件?
如题
TreeView在没有赋值NavigateUrl   的情况下,该事件可以触发。
但赋值后,就触发不了了。
请问怎么解决????

------解决方案--------------------
不知道楼主解决这个问题没有,我也是和你一样,设了NavigateUrl就不触发SelectedNodeChanged事件了,但后来我是从逻辑上解决这个问题的,
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
LoadRootNode();

}
}
private void LoadRootNode()
{
List<Navaigate.Model.tb_job> jobs = new Navaigate.BLL.tb_jobBLL().GetList("parentJobId = '0'");
foreach (Navaigate.Model.tb_job currentJob in jobs)
{
TreeNode rootNode = new TreeNode(currentJob.jobName, currentJob.jobID);
rootNode.NavigateUrl = "JobInfo.aspx?jobID=" + currentJob.jobID;

this.TreeView1.Nodes.Add(rootNode);
LoadAllJobsInfo(rootNode);
}
}
private void LoadAllJobsInfo(TreeNode node)
{
List<Navaigate.Model.tb_job> childJobs = new Navaigate.BLL.tb_jobBLL().GetList("parentJobId = '" + node.Value + "'");
foreach (Navaigate.Model.tb_job currentJob in childJobs)
{
TreeNode childNode = new TreeNode(currentJob.jobName, currentJob.jobID);
childNode.NavigateUrl = "JobInfo.aspx?jobID=" + currentJob.jobID;

//childNode.Target = "jobInfo";
node.ChildNodes.Add(childNode);
}
}
protected void TreeView1_SelectedNodeChanged(object sender, EventArgs e)
{
//if (this.TreeView1.SelectedNode == null)
// return;
//this.TreeView1.SelectedNode.NavigateUrl = "JobInfo.aspx?jobID=JOB001";// +currentJob.jobID;

//if (this.TreeView1.SelectedNode == null)
//{ return; }
//this.TreeView1.SelectedNode.ChildNodes.Clear();
//LoadAllJobsInfo(this.TreeView1.SelectedNode);
}

protected void TreeView1_TreeNodeExpanded(object sender, TreeNodeEventArgs e)
{
foreach (TreeNode currentNode in e.Node.ChildNodes)
{
LoadAllJobsInfo(currentNode);
}
}

反正触发这个事件,和我要导向的URL都是一个页面,我就不用他了,把值写到NavigateUrl里就得了,触发也没用,
不知道你是不是触发这个想加载下边的子节点?我是用屏开事件去做了SelectedNodeChanged事件的,在屏开时把下级的加载好,就不用选择时再加载了,这样就解决了用URL又用Selected事件