问题描述
usingSystem;usingSystem.Collections.Generic;usingSystem.Data;usingSystem.Text;usingSystem.Linq;usingSystem.Web;usingSystem.Web.UI;usingSystem.Web.UI.WebControls;usingBLL.Operation;namespaceWebGFMS.Pages.RoleManagement{publicpartialclassRoleManagement:System.Web.UI.Page{RolesOperationro=newRolesOperation();DataTabledt=newDataTable();protectedvoidPage_Load(objectsender,EventArgse){if(!IsPostBack){BindRoleList();}}#region绑定数据protectedvoidBindRoleList(){dt=ro.GetRoleIDAndName();gvRolesList.DataSource=dt;gvRolesList.DataBind();}#endregionprotectedvoidgvRolesList_PageIndexChanging(objectsender,GridViewPageEventArgse){gvRolesList.DataSource=ro.GetRoleIDAndName();gvRolesList.PageIndex=e.NewPageIndex;gvRolesList.DataBind();}protectedvoidgvRolesList_RowCommand(objectsender,GridViewCommandEventArgse){}protectedvoidgvRolesList_RowDataBound(objectsender,GridViewRowEventArgse){e.Row.Cells[0].Visible=false;if(e.Row.RowType==DataControlRowType.DataRow){CheckBoxListcbl=(CheckBoxList)e.Row.FindControl("MenusList");if(cbl!=null){MenusOperationmo=newMenusOperation();DataTabledt=newDataTable();dt=mo.GetAllMenu();cbl.DataSource=dt;cbl.DataTextField="MenuName";cbl.DataValueField="MenuID";cbl.DataBind();}}#region读取对应的权限,并勾选StringgetID=String.Empty;List<string>listResult=newList<string>();foreach(GridViewRowgvringvRolesList.Rows){getID=gvr.Cells[0].Text;MenusOperationmo=newMenusOperation();listResult=mo.GetMenuByRoleID(getID);foreach(ListItemliin(gvr.Cells[2].FindControl("MenusList")asCheckBoxList).Items){if(listResult!=null){foreach(varselectMenuinlistResult){if(li.Value.Equals(selectMenu)){li.Selected=true;break;}}}}}#endregion}}}