如何更新上传的图片

如何更新上传的图片

本文介绍了如何更新上传的图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

protected void Lnk_Edit_Click(object sender, EventArgs e)
        {
            Btn_Update.Visible = true;
            Btn_save.Visible = false;
            itemid = int.Parse(((LinkButton)sender).CommandArgument);
            GridViewRow row = (GridViewRow)((LinkButton)sender).Parent.Parent;




            TxtItemName.Text =row.Cells[2].Text;
            TxtDescription.Text = row.Cells[3].Text;
            //string ItemImgpath = Server.MapPath("~") + "\\Items_Image\\" + TxtItemName.Text + ".jpg";
            //FileUpload1.SaveAs(ItemImgpath);
            //string itemImagepath = "\\Items_Image\\" + TxtItemName.Text + ".jpg";
            iobj.Itemimage = "~/" + itemImagepath;

            TxtCost.Text = row.Cells[4].Text;
            TxtQuantity.Text = row.Cells[5].Text;
        }

        protected void Btn_Update_Click(object sender, EventArgs e)
        {
            iobj.Item_InsertUpdateDelete(itemid, int.Parse(DdlCategoryName.SelectedValue), TxtItemName.Text, TxtDescription.Text, iobj.Itemimage, int.Parse(TxtCost.Text), int.Parse(TxtQuantity.Text), 1);
            itemsgrid();
            ClientScript.RegisterStartupScript(this.GetType(), "Key", "alert('Items Updated Successfully');",true);
            Btn_save.Visible = true;
        }



在网格视图中,我正在显示所有详细信息.如果我单击编辑按钮,我应该编辑图像.



In grid view i am displaying all details. If i click edit button i should edit image. how to do it

推荐答案


protected void Btn_ImageUpdate_Click(object sender, EventArgs e)
       {
           string ItemImgpath = Server.MapPath("~") + "\\Items_Image\\" + TxtItemName.Text + ".jpg";
           FileUpload1.SaveAs(ItemImgpath);
           string itemImagepath = "\\Items_Image\\" + ".jpg";
           iobj.Itemimage = "~/" + itemImagepath;
           string sql =  string.Format("update ItemDetails set ItemImage='{0}' where ItemId='{1}'", iobj.Itemimage,itemid);
           iobj.updateImage(sql);
           itemsgrid();
           ClientScript.RegisterStartupScript(this.GetType(), "Key", "alert('Image Updated Successfully');", true);

       }


这篇关于如何更新上传的图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 23:22