<f:TemplateField Width="200px" HeaderText="角色">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# GetRolesName(Eval("Roles")) %>'></asp:Label>
</ItemTemplate>
/// <summary>
/// 获取用户角色Name值,在 ASPX 中调用
/// </summary>
/// <param name="gender"></param>
/// <returns></returns>
protected string GetRolesName(object roles)
{
HashSet<Role> r = roles as HashSet<Role>;
List<string> list = new List<string>();
for (int i = 0; i < r.Count;i++ )
{
Role rs= r.ToArray()[i];
list.Add(rs.Name);
}
return String.Join(",", list);
}