//一个权限段落

<div>
<asp:DataList ID="Menu" runat="server" OnItemDataBound="Menu_ItemDataBound" RepeatDirection="Horizontal">
    <ItemStyle VerticalAlign="Top" />
    <ItemTemplate>
        <div style="float:left; width:120px;">
            <div>
                <asp:CheckBox ID="opt" runat="server" onClick="onCheck(this);" Text='<%#Eval("MenuName") %>' />
                <a href="javascript:;" onclick="onView('<%#Eval("MenuNo") %>')" ><label style="color:Red; line-height:24px;" id="lbl_<%#Eval("MenuNo") %>">展开</label></a>
               
                <div style="margin-left:10px;" id="cont_<%#Eval("MenuNo") %>">
                   
<asp:CheckBoxList runat="server" ID="two_menu" name="two">
                       
                    </asp:CheckBoxList>

                </div>
            </div>
        </div>
    </ItemTemplate>
</asp:DataList>
</div>

 

 

rotected void Menu_ItemDataBound(object sender, DataListItemEventArgs e)
{//purview list
    string parent = Menu.DataKeys[e.Item.ItemIndex].ToString();
    BindPurview(parent, (CheckBoxList)e.Item.FindControl("two_menu"));
}

protected void BindPurview(string parent, CheckBoxList bb)
{
    ICollection<Org_SysSecMenusRecords> sMenu = org_second.getMenuByParent(parent);
    if (sMenu.Count > 0)
    {
        bb.DataSource = sMenu;
        bb.DataTextField = "ChildMenuName";
        bb.DataValueField = "ChildMenuNo";
        bb.DataBind();
    }
}

//绑定 checkboxlist的值

protected void BindPurviewSelected(int argid)
{
    employee.Value = argid.ToString();
    Org_UserRecords item = org_employees.SelectOrg_UserRecords(argid);
    //string[] purview = item.purview.Split(new char[] { ',' });
    string purview = item.purview;
    foreach (DataListItem oDataListItem in Menu.Items)
    {//注意这里. ListItem
        foreach (ListItem oListItem in ((CheckBoxList)oDataListItem.FindControl("two_menu")).Items)
        {
            if (purview.Contains(oListItem.Value)) {
                oListItem.Selected = true;
                ((CheckBox)oDataListItem.FindControl("opt")).Checked = true;
            }
        }
    }

 

 //得到checkboxlist的值

protected void purviewEdit()
{
    if (string.IsNullOrEmpty(employee.Value))
        return;

    string resultValue = string.Empty;
    foreach (DataListItem oDataListItem in Menu.Items)
    {
        if (((CheckBox)oDataListItem.FindControl("opt")).Checked)
        {
            foreach (ListItem item in ((CheckBoxList)oDataListItem.FindControl("two_menu")).Items)
            {
                if (item.Selected)
                    resultValue += item.Value + ",";
            }
        }
    }
    //resultValue.TrimEnd(new char[] { ',' });

    if (!org_employees.UpdateOrg_UserRecords("Org_UserRecords.purview", resultValue.TrimEnd(new char[] { ',' }), int.Parse(employee.Value)))
        lblRurviewError.InnerHtml = "An update error about purview";
}

 

//根据opt判断全选 

//注意获取父级node 然后判断全选

function onCheck(obj){
    var nextNode = obj.parentNode;
    var cb = nextNode.getElementsByTagName("input");
   
    for(var i=0;i<cb.length;i++){
        if(cb[i].type == "checkbox"){
            if(obj.checked){
                cb[i].checked = true;
            }
            else {
                cb[i].checked = false;
            }
        }
    }   
}