Adding roles to the 'CreateUserWizard'

前端 未结 3 551
星月不相逢
星月不相逢 2021-01-12 19:35

Hi (I\'m pretty new to this),

Is it possible to add roles to the \'CreateUserWizard\' tool so that you tick boxes (or view roles in a drop down menu) and once one or

3条回答
  •  逝去的感伤
    2021-01-12 19:54

    Add the dropdownlist under the last textbox of the CreateUserWizard as the following code shows. ASP:

                     <%---------existing items------------%>
                       
                            
                                Security Answer:
                            
                                
                                *
                            
                        
    
                        <%---------role Dropdownlist to be inserted here------------%>
                        Role
                            
                                
    
                        
    

    Also you have to add in behind code the following:

         protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {  
            ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("RoleDropDownList")).DataSource = Roles.GetAllRoles(); 
            ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("RoleDropDownList")).DataBind( );  
            int rolecounter = ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("RoleDropDownList")).Items.Count; 
            ((DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("RoleDropDownList")).Items[rolecounter - rolecounter].Selected = true;     
        }
    }
    protected void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
    {
        DropDownList roleDropDownList = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("RoleDropDownList");
        Roles.AddUserToRole(CreateUserWizard1.UserName, roleDropDownList.SelectedValue);
    }
    

    This is working for me.Check it

    see for more there http://p2p.wrox.com/asp-net-2-0-basics/42303-createuserwizard-dropdownlist.html

提交回复
热议问题