开发者

DetailsView image updating problem

开发者 https://www.devze.com 2023-04-04 05:12 出处:网络
I have DetailsView with users Info (Name, Email, Picture). That DetailsView control can be edited. Values are from DataBase

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消