Asp – How to change the checked property of a TreeViewNode In TreeView ,Its source is XMldataSource

asp.net

I have Connected an XmlDtaSource to a TreeView with checkboxes.I want to populate the user permissions in that.

 <asp:TreeView ID="TreeView1" runat="server" ExpandDepth="2" 
            ShowCheckBoxes="All" ShowLines="True">
            <DataBindings>
            <asp:TreeNodeBinding ValueField="Value" DataMember="menuNode" TextField="title" /> 

            </DataBindings> 

        </asp:TreeView>

I want to change the value of the checkbox(checked or not) according to the one field in the xml.
How to do this ? Plz

Best Solution

Do something like this

protected void Page_Load(object sender, EventArgs e)  
{  
    foreach (TreeNode node in TreeView1.Nodes)  
    {  
        SetNode(node);  
    }  
}  

void SetNode(TreeNode node)  
{  
    if (node.Text == "the condition for checked")  // Use node.DataItem to get your Id of bounded data and check your flag there in the actual data source using this Id. Probably you would like to have a function that returns bool.
    {  
        node.Checked = false;  
    }  
    if (node.ChildNodes.Count > 0)  
    {  
        foreach (TreeNode childnode in node.ChildNodes)  
        {  
            SetNode(childnode);  
        }  
    }  
}  

I've not provided exact answer by hope it give you some clue.

Related Question