You've told the membership system to delete the user you're logged in as. You therefore shouldn't be surprised when it deletes the user you're logged in as! :)
To delete the member selected in the GridView, you need to pass the username for that user to the
DeleteUser
method instead.
Start by setting the
DataKeyNames property[
^] on the GridView:
<asp:GridView ... DataKeyNames="UserName">
Then use
the correct EventArgs type[
^] for the
RowDeleting event handler[
^]:
protected void gvwUsers_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
...
}
Then, you will be able to retrieve the key of the row being deleted, and pass that to the
DeleteUser
method:
protected void gvwUsers_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string userToDelete = (string)e.Keys["UserName"];
Membership.DeleteUser(userToDelete, true);
}