TreeView 不刷新获得节点值的方法 --- asp.net 2.0

http://hi.baidu.com/haoyongsheng/blog/item/73155795d309e90e7bf480e9.html

网上找了半天,好像有人提到过这个东西,可是自己实现起来,却不是那么容易,

做法也很简单,就是js完成选择工作:

<script type="text/javascript">

function myalert(a)
{
alert(a);
document.getElementById('Knowledge').value=a;
}

</script>

。。。。。

<asp:TextBox ID="Knowledge" runat="server"></asp:TextBox>

。。。。。

 

.cs 代码片段:

    void PopulateZhang(TreeNode node)
    {
        if (node.ChildNodes.Count == 0)
        {
            if (node.Value != null)
            {

                string tmpSql = "select distinct(Z_ID),zhang from zhang_jie_dianView where Sub_ID=" + node.Value;

                DataSet ResultSet = db.ExecuteDataSet(tmpSql);

                if (ResultSet.Tables.Count > 0)
                {
                    foreach (DataRow row in ResultSet.Tables[0].Rows)
                    {
                        if (row["zhang"].ToString() != "")
                        {

                            TreeNode NewNode = new TreeNode(row["zhang"].ToString());

                            NewNode.Text = "<a menu=menu2 onclick=\"myalert('" + row["zhang"].ToString() + "')\">" + row["zhang"].ToString() + "</a>";

//注意这里的单引号,和双引号,我也费了很长事件才调试出来

                            NewNode.Value = row["Z_ID"].ToString();

                            NewNode.PopulateOnDemand = true;

                            NewNode.SelectAction = TreeNodeSelectAction.Select;

                            NewNode.NavigateUrl = "";

                            node.ChildNodes.Add(NewNode);
                            node.CollapseAll();
                        }
                    }
                }
            }
        }
    }

posted @ 2009-11-22 22:20  chaobj  阅读(1355)  评论(0编辑  收藏  举报