2010-02-03 52 views
0

我已將XmlDtaSource連接到TreeView並帶有複選框。我想在其中填充用戶權限。如何更改TreeViewNode的checked屬性在TreeView中,它的源代碼是XMldataSource?

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

      </DataBindings> 

     </asp:TreeView> 

我想根據xml中的一個字段更改複選框的值(選中或不選)。 如何做到這一點? PLZ

回答

0

做這樣的事情

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); 
     } 
    } 
} 
我不希望它給你一些線索提供確切的答案

相關問題