Have a gridview that lists users who are locked out of the system. Admin staff can go on to this unlockuser page where the gridview will be displayed with the users various details, theres an unlock button on every row for each user. Just wondering what way to write the back end code for the gridview row command? So far I have

  MembershipUser usr = Membership.GetUser();
                usr.UnlockUser();

How do I get the user id into this? Do I need to declare it as a variable somewhere in the code behind?

In your gridview itemtemplate button, you should add the commandArgument, like this:

<asp:button .... CommandArgument='<%#Eval("UserId") %>' />

Then, in the BackEnd, on your RowCommand event, you can get the userId like this:

int UserId = int.Parse(e.CommandArgument.ToString())

Thats great, thank you. Any idea how I update the database table so that the isLockedOut field changes to false and then update the gridview to display the remaining locked out users?

I never used asp.net membership providers, so I can't help much with that.

But in plain SQL, it would be like this:

UPDATE [myUserTable] SET [myLockedField] = 0 WHERE [myUserIdField] = @UserId

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.