RolesManage.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="RolesManage.aspx.cs" Inherits="SystemManagment_RolesManage" Debug="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 100%;
}
.style2
{
width: 170px;
}
.style3
{
width: 100px;
}
</style>
<script>
</script>
</head>
<body>
<form id="form1" runat="server">
<input id="hdnEmailID" type="hidden" name="hdnEmailID" value="0" runat=server />
<div>
<table class="style1">
<tr>
<td>
</td>
</tr>
<tr>
<td align="center">
角色管理</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td>
<table class="style1">
<tr>
<td align="right">
角色名称:</td>
<td class="style2">
<asp:TextBox ID="RoleName" runat="server"></asp:TextBox>
</td>
<td class="style3">
<asp:Button ID="AddRole" runat="server" Text="添加角色" />
</td>
<td>
<asp:Button ID="DeleteRole" runat="server" Text="删除角色" />
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
</td>
</tr>
<tr>
<td align="center">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" Width="289px" OnRowDataBound="Gridview_RowDataBound">
<Columns>
<asp:BoundField HeaderText="角色名称" DataField="RoleName" />
</Columns>
<AlternatingRowStyle BackColor="#D2E9FF" />
</asp:GridView>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>
RolesManage.aspx.cs
using System;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;
using System.Configuration;
using System.Web.Security;
public partial class SystemManagment_RolesManage : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ShowRoles();
}
}
protected void ShowRoles()
{
string[] RolesArray = Roles.GetAllRoles();
DataTable AllRolesTable = new DataTable();
AllRolesTable.Columns.Add("RoleName",typeof(string));
foreach (string RoleName in RolesArray)
{
DataRow NewRow = AllRolesTable.NewRow();
NewRow[0] = RoleName; //第一处
AllRolesTable.Rows.Add(NewRow);
}
GridView1.DataSource = AllRolesTable;
GridView1.DataBind();
}
protected void Gridview_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.ID = e.Row.Cells[0].Text; //第二处1
e.Row.Attributes.Add("onclick", "GridView_selectRow(this,"+e.Row.Cells[0].Text+")"); //第二处2
}
}
protected void AddRole_Click(object sender, EventArgs e)
{
try
{
Roles.CreateRole(RoleName.Text);
ShowRoles();
}
catch
{
throw;
}
}
protected void DeleteRole_Click(object sender, EventArgs e)
{
Roles.DeleteRole(hdnEmailID.Value); //第三处
ShowRoles();
}
}