权限管理时的分层显示
做权限管理的时候遇到的问题,想让明细权限按模块名称纵向排列后再绑定到DataGird,解决方法如下:
select * from(
select ID, 权限名称,模块名称,菜单名称,权限地址,模块序号 from T_sys_right_info
as T1
union
select '0' as ID,模块名称 as 权限名称,
模块名称,模块名称 as 菜单名称,模块名称 as 权限地址 ,模块序号
from ( select distinct top 50 模块名称,模块序号 from T_sys_right_info order by 模块序号,模块名称 )
AS T2
)
as T3
order by T3.模块序号,T3.模块名称
表结构: select ID, 权限名称,模块名称,菜单名称,权限地址,模块序号 from T_sys_right_info
as T1
union
select '0' as ID,模块名称 as 权限名称,
模块名称,模块名称 as 菜单名称,模块名称 as 权限地址 ,模块序号
from ( select distinct top 50 模块名称,模块序号 from T_sys_right_info order by 模块序号,模块名称 )
AS T2
)
as T3
order by T3.模块序号,T3.模块名称
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[T_Sys_Right_Info]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[T_Sys_Right_Info]
GO
CREATE TABLE [dbo].[T_Sys_Right_Info] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[权限名称] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[模块名称] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[菜单名称] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[权限地址] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[模块序号] [int] NOT NULL ,
[菜单序号] [int] NOT NULL
) ON [PRIMARY]
GO
然后在DataGrid的DataItemBound事件做处理,如果是模块名称的行,则只显示其中一列,并加入ColSpan
drop table [dbo].[T_Sys_Right_Info]
GO
CREATE TABLE [dbo].[T_Sys_Right_Info] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[权限名称] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[模块名称] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[菜单名称] [nvarchar] (20) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[权限地址] [nvarchar] (100) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[模块序号] [int] NOT NULL ,
[菜单序号] [int] NOT NULL
) ON [PRIMARY]
GO