编辑更新成员中的删除
问题描述:
我正在为admin创建页面以查看系统数据库中的所有用户。我正在使用网格视图来检索成员资格表中的所有用户。现在的问题是管理员如何编辑,删除和更新管理员所做的更改?当我们想要配置select语句时,有一个advance按钮,我们可以添加一些额外的语句。我的SQL中的成员表没有主键。我该如何解决这个问题?非常感谢。编辑更新成员中的删除
答
这教程,阿什温建议看起来太参与我。我将采取的方向...
将用户名字段存储在gridview的datakey属性中。并使用网格视图的RowDeleting和RowUpdating事件......
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
e.Cancel = true; // cancel default action.
// delete user myself.
string user = e.Keys["username"].ToString(); // think that's the name of the field in database.
Membership.DeleteUser(user);
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
e.Cancel = true; // cancel default action.
// update user myself.
var userToUpdate = new MembershipUser();
// get new values with e.NewValues[] and fill out all properties of userToUpdate.
Membership.UpdateUser(userToUpdate);
}
从调用成员对象的方法似乎在我看来很容易,然后你不必与表是asp.net混乱如果做得不正确,会产生一些可能导致问题的东西
没有主键?然后你的数据库被错误地解决了。如果没有主键,一切都会搞砸,你将很难执行CRUD操作,查询性能低下等。发布表结构后,你会得到更好的答案。 – Yaroslav 2012-07-12 06:51:08
它有一个主键。这是一个很长的丑陋的GUID字段。 – Theo 2012-07-12 07:12:38