|
Server User and Groups Grid
This article is an example on how you can combine various features of .Net
framework to display server or domain users and groups in an ASP.Net DataGrid
control. This grid is implemented based on our previous article,
Embdding DataList in DataGrid, where we showed how a DataList
control can be embedded inside DataGrid. In this article we show
members of a group in DataList embedded master grid showing group
details. And in NTUsers.aspx page we show user's group memebership
in a DataList embedded in master grid showing windows user
information.
Store Server Groups and Users in an ADO.Net DataSet
The very first thing that you would need to build an application to display
users and groups information is to get this data from the system. We used DirectoryServices
classes with WinNT provider to get the data. Instead of getting the data
every time, we have built a set of DataTable objects stored in a
DataSet. This data set is stored in Cache for 30 minutes.
After that we refresh the information. In the demo project you will see that
there are following DataTable objects with complete set of
constraints and unique primary keys.
-
NTUsers - This
DataTable contains all the users. The
primary key of this table is user's SID.
-
NTGroups - This
DataTable contains all the groups in your
system. The primary key for this table id groups SID.
-
GroupMembers - This
DataTable contains records for memebers
of a every group. This table has a combined primary key based on user's SID and
group SID.
Both NTUsers and NTGroups tables have relation with GroupMembers
table in the data set.
The rest of the implementation is based on our previous grid formatting
articles. The grids are bound to tables in the data set. The embeded data list
controls are populated in ItemDataBound event of the data grid
controls. In the event handler we use CreateChildView method to
get data from relational tables.
private void OnUserGridDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.AlternatingItem ||
e.Item.ItemType == ListItemType.Item)
{
Control obCtl = e.Item.FindControl("Members_DataList");
if (null != obCtl && obCtl is DataList)
{
DataRowView drv = (DataRowView)e.Item.DataItem;
DataView dv = drv.CreateChildView("rel_Groups");
if (null != dv)
{
Members_DataList = (DataList)obCtl;
Members_DataList.ItemDataBound +=
new DataListItemEventHandler(this.Groups_DataList_ItemDataBound);
Members_DataList.DataSource = dv;
Members_DataList.DataBind();
}
}
}
}
|