Coolite在后台动态加载CheckboxGroup,页面显示都正常,但是在后台去获取选中的checkbox时,使用下方法:
/// <summary>
/// 获取所选权限
/// </summary>
/// <returns></returns>
private string GetPermissionValue()
{
string str = string.Empty;
cbgPermission.CheckedItems.ForEach(delegate(Checkbox checkbox)
{
if (string.IsNullOrEmpty(str))
str = checkbox.ID;
else
str += "," + checkbox.ID;
});
return str;
}
/// 获取所选权限
/// </summary>
/// <returns></returns>
private string GetPermissionValue()
{
string str = string.Empty;
cbgPermission.CheckedItems.ForEach(delegate(Checkbox checkbox)
{
if (string.IsNullOrEmpty(str))
str = checkbox.ID;
else
str += "," + checkbox.ID;
});
return str;
}
跟踪后发现获取的cbgPermission.CheckedItems一直为0.
解决方法:
可是是Coolite页面加载的问题,将动态加载checkbox的方法
代码
/// <summary>
/// 绑定系统所有权限
/// </summary>
private void PartBinder()
{
IList<SystemPermission> parts = SystemPermissionBLL.GetALL("ParentCode='0'", "Code");
if (parts != null && parts.Count > 0)
{
foreach (SystemPermission part in parts)
{
CheckboxColumn col = new CheckboxColumn();
col.ID = "CheckboxColumn" + part.SPId;
col.ColumnWidth = Convert.ToDouble(0.33);
Checkbox checkbox = new Checkbox();
checkbox.ID = part.Code;
checkbox.IDMode = IDMode.Explicit;
checkbox.BoxLabel = part.Name;
checkbox.Checked = true;
col.Items.Add(checkbox);
IList<SystemPermission> items = SystemPermissionBLL.GetALL("ParentCode='" + part.Code + "'", "Code");
if (items.Count > 0 && items != null)
{
foreach (SystemPermission item in items)
{
Checkbox checkboxChild = new Checkbox();
checkboxChild.ID = item.Code;
checkboxChild.BoxLabel = item.Name;
col.Items.Add(checkboxChild);
}
}
cbgPermission.Items.Add(col);
}
}
}
/// 绑定系统所有权限
/// </summary>
private void PartBinder()
{
IList<SystemPermission> parts = SystemPermissionBLL.GetALL("ParentCode='0'", "Code");
if (parts != null && parts.Count > 0)
{
foreach (SystemPermission part in parts)
{
CheckboxColumn col = new CheckboxColumn();
col.ID = "CheckboxColumn" + part.SPId;
col.ColumnWidth = Convert.ToDouble(0.33);
Checkbox checkbox = new Checkbox();
checkbox.ID = part.Code;
checkbox.IDMode = IDMode.Explicit;
checkbox.BoxLabel = part.Name;
checkbox.Checked = true;
col.Items.Add(checkbox);
IList<SystemPermission> items = SystemPermissionBLL.GetALL("ParentCode='" + part.Code + "'", "Code");
if (items.Count > 0 && items != null)
{
foreach (SystemPermission item in items)
{
Checkbox checkboxChild = new Checkbox();
checkboxChild.ID = item.Code;
checkboxChild.BoxLabel = item.Name;
col.Items.Add(checkboxChild);
}
}
cbgPermission.Items.Add(col);
}
}
}
放入到重写的页面createChildControl中去,而不是放在pageload中。
protected override void CreateChildControls()
{
PartBinder();
base.CreateChildControls();
}
{
PartBinder();
base.CreateChildControls();
}
完成