Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6991151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T19:27:25+00:00 2026-05-27T19:27:25+00:00

I have a RadioButtonList chklRoles which has 4 buttons. I want to update database

  • 0

I have a RadioButtonList “chklRoles” which has 4 buttons. I want to update database aspnet_UserInRoles if I select a role. But it seems that the Aspnet Membership Provider doesn’t have an update method. How can I do it?

 protected void chklRoles_SelectedIndexChanged(object sender, EventArgs e)
    {
        foreach (string role in Roles.GetRolesForUser(userName))
        {
            if (chklRoles.Items.FindByText(role).Selected == true)
            {  
                // update role;
               // Roles.DeleteRole("origin_role");
               //  Roles.AddUserToRole(userName, role);
            }
        }
    }

Edit: I think that to delete it and add it with a new role maybe an option. But please give me an advice.
update: each user only can have one role. What I want is how to switch roles by clicking the radio button. Update meants a new role will replace the older role.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T19:27:26+00:00Added an answer on May 27, 2026 at 7:27 pm

    You can use the RoleProvider to add or remove roles from a user. You’ll have to determine what roles are to be added and/or removed. That would look something like this:

    protected void chklRoles_SelectedIndexChanged(object sender, EventArgs e)
    {
        var current = Roles.GetRolesForUser(userName);
        var added = new List<string>();
        var removed = new List<string>();
    
        // go over all the roles to build the lists 
        foreach (string role in Roles.GetAllRoles())
        {
            if (chklRoles.Items.FindByText(role).Selected && !current.Contains( role ))
            {  
                added.Add( role );
            }
            else if( current.Contains( role ) )
            {
                removed.Add( role );
            }
        }
        // apply changes if needed
        if( added.Count > 0 )
        {
           Roles.AddUsersToRoles( new[]{userName}, added.ToArray());
        }
        if( removed.Count > 0 )
        {
            Roles.RemoveUsersFromRoles(new[]{userName}, removed.ToArray());
        }
    }
    

    Note that I haven’t had a chance to check this code thoroughly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a RadioButtonList which contain 4 radio buttons A,B,C,D RBQ.Items.Add("A") RBQ.Items.Add("B") RBQ.Items.Add("C") RBQ.Items.Add("D")
I have an asp:radiobuttonlist that serves two purposes depending on which button is pushed.
I have four RadioButtonList and I want to select input:radio from them. I use
I have a RadioButtonList which has AutoPostBack set to True and is being handled
I have Page in which I use a RadiobuttonList that is in an HTML
I have a Gridview in which one of the template fields has a radiobuttonlist
I have a custom control which has a RadioButtonList control in it. On selecting
I have an asp:RadioButtonList and want to declaratively bind the value to an enumeration.
I have a page that add Items to RadioButtonList with this code : Protected
I have a DataList that Displays some Posts with a RadioButtonList inside where it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.