【发布时间】:2014-12-17 05:12:24
【问题描述】:
我有一个带有每个节点复选框的树视图控件。每个节点代表一个部门。我希望默认情况下应选择主要部门及其子部门。 下面是控制代码:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:LinkButton runat="server" ID="lnkSelectAllDepartments" Text="Select All" OnClick="lnkSelectAllDepartments_Click" Font-Bold="false" Font-Underline="true"></asp:LinkButton>|
<span class="labelText" style="font-weight:bold"> | </span>
<asp:LinkButton runat="server" ID="lnkDeselectAllDepartments" Text="Deselect All" OnClick="lnkDeselectAllDepartments_Click" Font-Bold="false" Font-Underline="true"></asp:LinkButton>
<br />
<br />
<asp:CheckBoxList ID="listDepartment" runat="server" Height="120px" RepeatDirection="Vertical" RepeatLayout="Flow"> </asp:CheckBoxList>
<asp:TreeView ID="tvDepartments" runat="server" ShowCheckBoxes="All" ShowExpandCollapse="true" ExpandDepth=0 NodeStyle-ForeColor="Black" ></asp:TreeView>
</ContentTemplate>
</asp:UpdatePanel>
下面的代码是后面的代码:
/*Added for TreeView control...*/
string rootDepartmentName = ConfigurationReader.ParentDepartmentName; /
if (lstDepartmentDetails.Any(item => item.Name.CompareString(rootDepartmentName) && item.ParentName.IsNullOrEmpty()))
{
clsRelFilter rootDepartment = lstDepartmentDetails.FirstOrDefault(item => item.Name.CompareString(rootDepartmentName) && item.ParentName.IsNullOrEmpty());
TreeNode ParentNode = new TreeNode(rootDepartment.Name, rootDepartment.Uri);
AddChildDepartmentsToNode(ParentNode, rootDepartment, lstDepartmentDetails);
tvDepartments.Nodes.Add(ParentNode);
}
【问题讨论】: