ASP.NET中 Treeview控件 启用了checkbox
ASP.NET中Treeview控件启用了checkbox无法实现父节点的checkbox选中的同时选中所属的子节点,怎激发checkbox的changed事件?...
ASP.NET中 Treeview控件 启用了checkbox 无法实现父节点的checkbox选中的同时选中所属的子节点,怎激发checkbox的changed事件?
展开
1个回答
展开全部
大概的代码 你可以自己修改一下
后台:
protected void Page_Load(object sender, EventArgs e)
{
TreeView1.Attributes.Add("onclick", "postBackObject()");
}
protected void node_CheckChange(object sender, TreeNodeEventArgs e)
{
SetCheck(e.Node);
}
protected void SetCheck(TreeNode tn)
{
if (tn.Checked)
{
foreach (TreeNode subtn in tn.ChildNodes)
{
subtn.Checked = true;
SetCheck(subtn);
}
}
}
前台:
<head>
<title></title>
<script type="text/javascript">
function postBackObject() {
var o = window.event.srcElement;
if (o.type == "checkbox") {
__doPostBack("", "");
}
}
</script>
</head>
<asp:TreeView OnTreeNodeCheckChanged="node_CheckChange" ID="TreeView1" runat="server">
<Nodes>
<asp:TreeNode ShowCheckBox="true" Value="父节点">
<asp:TreeNode ShowCheckBox="true" Value="子节点1">
<asp:TreeNode ShowCheckBox="true" Value="子节点11"></asp:TreeNode>
<asp:TreeNode ShowCheckBox="true" Value="子节点22"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode ShowCheckBox="true" Value="子节点2"></asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
后台:
protected void Page_Load(object sender, EventArgs e)
{
TreeView1.Attributes.Add("onclick", "postBackObject()");
}
protected void node_CheckChange(object sender, TreeNodeEventArgs e)
{
SetCheck(e.Node);
}
protected void SetCheck(TreeNode tn)
{
if (tn.Checked)
{
foreach (TreeNode subtn in tn.ChildNodes)
{
subtn.Checked = true;
SetCheck(subtn);
}
}
}
前台:
<head>
<title></title>
<script type="text/javascript">
function postBackObject() {
var o = window.event.srcElement;
if (o.type == "checkbox") {
__doPostBack("", "");
}
}
</script>
</head>
<asp:TreeView OnTreeNodeCheckChanged="node_CheckChange" ID="TreeView1" runat="server">
<Nodes>
<asp:TreeNode ShowCheckBox="true" Value="父节点">
<asp:TreeNode ShowCheckBox="true" Value="子节点1">
<asp:TreeNode ShowCheckBox="true" Value="子节点11"></asp:TreeNode>
<asp:TreeNode ShowCheckBox="true" Value="子节点22"></asp:TreeNode>
</asp:TreeNode>
<asp:TreeNode ShowCheckBox="true" Value="子节点2"></asp:TreeNode>
</asp:TreeNode>
</Nodes>
</asp:TreeView>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询