I have DetailsView with users Info (Name, Email, Picture). That DetailsView control can be edited. Values are from DataBase
protected void DVUserInfoShow_ItemUpdating(object sender, DetailsViewUpdateEventArgs e)
{
FileUpload EditAvatar = (FileUpload)DVUserInfoShow.FindCont开发者_Python百科rol("EditAvatar");
if (EditAvatar.HasFile)
{
string image_path = "~/images/user_images/" + EditAvatar.FileName;
EditAvatar.SaveAs(Server.MapPath(image_path));
e.NewValues["Avatar"] = EditAvatar.FileName;
}
else
{
e.NewValues["Avatar"] = e.OldValues["Avatar"];
}
}
The problem is with e.NewValues["Avatar"] = e.OldValues["Avatar"];, when user updates his name and email, the picture value is set to null. And that code doesn't work. What I'm doing wrong?
OldValues
collection is only available when DetailView
is bounded with a declarative DataSource
, otherwise OldValues
collection will contain null
in ItemUpadting
event.
What you can do is inside DVUserInfoShow_ItemUpdating
event, get current data from database and save in some local variables.
精彩评论