0

我试图允许用户从包含所有角色的下拉列表中选择 createuserwizard 上的角色。我没有收到错误,但无论选择什么下拉列表项,用户总是添加到“提供房间”角色。

代码:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        roleDropDownList = RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("RoleDropDownList")
        roleDropDownList.DataSource = Roles.GetAllRoles()
        roleDropDownList.DataBind()
    End Sub

    Protected Sub RegisterUser_CreatedUser(ByVal sender As Object, ByVal e As EventArgs) Handles RegisterUser.CreatedUser         
        Roles.AddUserToRole(RegisterUser.UserName, roleDropDownList.SelectedValue)         
    End Sub

标记:

<asp:DropDownList ID="RoleDropDownList" runat="server">

                                </asp:DropDownList>

html:

<option value="Offering Rooms">Offering Rooms</option>
<option value="Seeking Rooms">Seeking Rooms</option>
4

1 回答 1

2

您需要添加检查这是否是回发而不是再次绑定:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
     If Not IsPostBack Then        
        roleDropDownList = RegisterUser.CreateUserStep.ContentTemplateContainer.FindControl("RoleDropDownList")
        roleDropDownList.DataSource = Roles.GetAllRoles()
        roleDropDownList.DataBind()
     End If
End Sub
于 2012-07-19T14:09:55.080 回答