【发布时间】:2011-07-29 11:52:08
【问题描述】:
大家好,我有一个页面显示住宿信息,然后是在 DetailsView 中创建该信息的人的用户 ID。
我还有一个按钮,应该查看那个用户 ID,当点击该用户 ID 时,将该用户 ID 转换为用户名,以便我可以使用该用户名将人员角色更改为租户。但是我不确定使用 C# 如何从详细信息视图中获取用户 ID 进行转换并更新角色。有什么想法吗?
标记
@蒂姆
这是我添加的代码:
public partial class adminonly_approval : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
void DetailsView1_ItemCommand(Object sender, DetailsViewCommandEventArgs e){
if (e.CommandName == "SetToRenter")
{
// if UserID is in second row:
DetailsViewRow row = DetailsView1.Rows[9];
// Get the Username from the appropriate cell.
// In this example, the Username is in the second cell
String UserID = row.Cells[9].Text;
MembershipUser memUser = Membership.GetUser(UserID);
Roles.AddUserToRole(memUser.UserName, "renter");
}
}
我在详细信息视图下方的页面上添加了一个按钮,并将 commandName 设置为 SetToRenter。当我单击按钮时,虽然它没有改变角色。我是 ASP 和 C# 的新手,但在大学作业中需要此功能。 任何想法?
【问题讨论】: