【发布时间】:2019-06-10 23:58:12
【问题描述】:
我正在尝试使用 C# 在 .NET 中生成动态嵌套 CheckBoxLists。
我想在每个部门和区域旁边显示一个复选框。当一个部门的复选框被选中时,它应该在其正下方显示该部门的区域,缩进,旁边有复选框。
我可以动态生成带有复选框的部门,但我不确定如何处理这些区域。部分问题是我没有每个部门的个人 ID,它只是一个列表。
<div class="TABLE">
<div class="ROW">
<div class="CELL CELL50">
<asp:CheckBoxList id="cblDepts" runat="server" OnSelectedIndexChange="cblDepts_OnSelectedIndexChange"></asp:CheckBoxList>
</div>
<div class="CELL CELL50">
<asp:CheckBoxList id="cblAreas" runat="server" Visible="false">
</asp:CheckBoxList>
</div>
</div>
</div>
protected void LoadFilters()
{
_datalayer = new DataLayer();
deptAreas = new Dictionary<string, Tuple<string, string>>();
Dictionary<string, string> depts = new Dictionary<string, string>();
DataSet dsDepts = _datalayer.GetDepartments();
if(dsDepts != null && dsDepts.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in dsDepts.Tables[0].Rows)
{
depts.Add(dr["DepartmentId"].ToString(), dr["DepartmentDetails"].ToString());
}
}
this.cblDepts.Items.Clear();
this.cblAreas.Items.Clear();
foreach(var dept in depts)
{
this.cblDepts.Items.Add(new ListItem(dept.Value, dept.Key));
DataSet dsAreas = _datalayer.GetAreas(dept.Key.ToChange<int>().Value);
if(dsAreas != null && dsAreas.Tables[0].Rows.Count > 0)
{
foreach (DataRow dr in dsAreas.Tables[0].Rows)
{
deptAreas.Add(dept.Key, Tuple.Create(dr["AreaId"].ToString(), dr["AreaDetails"].ToString()));
}
}
}
}
结果应该是,当您单击部门旁边的复选框时,该部门的区域显示在该部门下方,缩进,每个旁边都有一个复选框。
【问题讨论】: