如何更新上传的图片 [英] How to update uploaded image

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

问题描述

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

推荐答案

我应该编辑图像.
如何更新上传的图片
通过提供浏览按钮来上传新图像.与插入/添加过程类似,只是在更新过程中与此映像关联的唯一ID已经存在.

因此,如果您提供了用于首次上传的文件上传控件,则在编辑过程中-提供文件上传控件,并且如果选择了任何内容,则将旧的替换为新的.
i should edit image.
How to update uploaded image
By providing a browse button to upload a new image. Similar to insert/add procedure, just that the unique ID associated with this image during update already exists.

So, if you provided a file upload control for uploading first time, during edit - provide file upload control and if anything selected then replace old one with new one.


保护的void Lnk_Edit_Click(对象发送者,EventArgs e)
{
Btn_Update.Visible = true;
Btn_save.Visible = false;
itemid = int.Parse((((LinkBut​​ton)sender).CommandArgument);
GridViewRow row =(GridViewRow)((LinkBut​​ton)sender).Parent.Parent;

图片img =(图片)row.FindControl("Imgitem");
Image1.ImageUrl = img.ImageUrl;
pnlImage.Visible = true;

TxtItemName.Text = row.Cells [2] .Text;
TxtDescription.Text = row.Cells [3] .Text;

FileUpload1.Visible = false;
iobj.Itemimage =〜/" + itemImagepath;


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

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;

Image img = (Image)row.FindControl("Imgitem");
Image1.ImageUrl = img.ImageUrl;
pnlImage.Visible = true;

TxtItemName.Text =row.Cells[2].Text;
TxtDescription.Text = row.Cells[3].Text;

FileUpload1.Visible = false;
iobj.Itemimage = "~/" + itemImagepath;


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

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);

       }


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆