检查复选框后,asp.net中的treeview控件的TreeNodeCheckChanged事件未触发

时间:2011-08-22 10:53:59

标签: c# asp.net treeview

选中复选框后,TreeNodeCheckChanged事件未触发。

Boolean flag;

protected void TreeView1_TreeNodeCheckChanged(object sender, TreeNodeEventArgs e)
{
    Label1.Text = "check event fired";
    TreeView1.SelectedNode.Checked = true;
    if (flag)
    {
        foreach (TreeNode child in TreeView1.SelectedNode.ChildNodes)
        {
            child.Checked = true;
        }
    }
    else
    {
        TreeView1.SelectedNode.Checked = false;
        foreach (TreeNode child in TreeView1.SelectedNode.ChildNodes)
        {
            child.Checked = false;
        }
    }
}

1 个答案:

答案 0 :(得分:3)

经过一番研究,我发现that:这似乎是你想要的。 :)

记录的代码:

<script language="javascript" type="text/javascript">  
function postbackOnCheck() 
{ 
    var o = window.event.srcElement; 
    if (o.tagName == 'INPUT' && o.type == 'checkbox' && o.name != null && o.name.indexOf('CheckBox') > -1) 
        { __doPostBack("",""); } }  
</script>  
<asp:TreeView onclick="postbackOnCheck()" ID="treeContent"
runat="server"> ... And so on ... </TreeView>