Filtered
asked on
Can't Update Members database Membership.UpdateUser
Hi
I have been having a problem updating the ASPNETDB.MDF Created by Visual Studio when creating Membership forms like login new user etc
I Have created a GridView to edit existing user in this database updating Roles works but when i try to Update fields like Email or ISApproved it is not save the changes to the database
protected void gdvEdit_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int intIndex = Convert.ToInt32(e.RowIndex );
TextBox txtUserName = (TextBox)gdvEdit.Rows[intI ndex].Find Control("t xtUserName ");
TextBox txtEmail = (TextBox)gdvEdit.Rows[intI ndex].Find Control("t xtEmail");
CheckBox chkEditIsLockedOut = (CheckBox)gdvEdit.Rows[int Index].Fin dControl(" chkEditIsL ockedOut") ;
ListBox lsbRoles = (ListBox)gdvEdit.Rows[intI ndex].Find Control("l sbRoles");
//Remove all Roles From User
string[] userRoles = Roles.GetRolesForUser(gdvE dit.DataKe ys[intInde x][0].ToSt ring());
foreach (string strRole in userRoles)
{
Roles.RemoveUserFromRole(g dvEdit.Dat aKeys[intI ndex][0].T oString(), strRole);
}
//Replace with new selection of roles
for (int i = 0; i < lsbRoles.Items.Count; i++)
{
if (lsbRoles.Items[i].Selecte d == true)
Roles.AddUserToRole(gdvEdi t.DataKeys [intIndex] [0].ToStri ng(), lsbRoles.Items[i].Value);
}
string UserName = gdvEdit.DataKeys[intIndex] [0].ToStri ng();
MembershipUser UserDetails = Membership.GetUser(UserNam e);
//Update User Details
UserDetails.IsApproved = true;
UserDetails.Email = txtEmail.Text.Trim();
if (chkEditIsLockedOut.Checke d == false) { UserDetails.UnlockUser(); }
Membership.UpdateUser(User Details);
//Rebind GridView
gdvEdit.EditIndex = -1;
Bind_gdvEdit();
}
Any Ideas on why this maybe happing would be appreciated
Thanks
John
I have been having a problem updating the ASPNETDB.MDF Created by Visual Studio when creating Membership forms like login new user etc
I Have created a GridView to edit existing user in this database updating Roles works but when i try to Update fields like Email or ISApproved it is not save the changes to the database
protected void gdvEdit_RowUpdating(object
{
int intIndex = Convert.ToInt32(e.RowIndex
TextBox txtUserName = (TextBox)gdvEdit.Rows[intI
TextBox txtEmail = (TextBox)gdvEdit.Rows[intI
CheckBox chkEditIsLockedOut = (CheckBox)gdvEdit.Rows[int
ListBox lsbRoles = (ListBox)gdvEdit.Rows[intI
//Remove all Roles From User
string[] userRoles = Roles.GetRolesForUser(gdvE
foreach (string strRole in userRoles)
{
Roles.RemoveUserFromRole(g
}
//Replace with new selection of roles
for (int i = 0; i < lsbRoles.Items.Count; i++)
{
if (lsbRoles.Items[i].Selecte
Roles.AddUserToRole(gdvEdi
}
string UserName = gdvEdit.DataKeys[intIndex]
MembershipUser UserDetails = Membership.GetUser(UserNam
//Update User Details
UserDetails.IsApproved = true;
UserDetails.Email = txtEmail.Text.Trim();
if (chkEditIsLockedOut.Checke
Membership.UpdateUser(User
//Rebind GridView
gdvEdit.EditIndex = -1;
Bind_gdvEdit();
}
Any Ideas on why this maybe happing would be appreciated
Thanks
John
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
ASKER
Thank you very much joechina that has done the trick :)
ASKER
If anyone would like me to send them the project (it is quite small only has few pages and the database) so that they could step through the code and detect something that i'm unaware of i will gladly send it to them by email as I can not upload the project to this site even as a zip file.
Thanks
John