如何将图像插入到formview中 [英] How do I insert image into formview

查看:57
本文介绍了如何将图像插入到formview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有里面的formview我去插入和抓取上传上传图片但是我上传的时间我将只得到真实的话



所以一些1帮助PLZ





这是用于将图像路径插入文本框



不要判断我这是新来的,所以你可以解决它



我尝试过:



hello i have formview inside it i go for insert and grab upload to upload image but evey time i upload i will get only words "True"

so some 1 help plz


this is for insert the image path into textbox

don't judge me iam new at this so can u fix it

What I have tried:

protected void LinkButton1_Click(object sender, EventArgs e)
{
    FileUpload newfileuploadcontrol = (FileUpload)FormView1.FindControl("FileUpload1") as FileUpload;
    TextBox newtextbox = (TextBox)FormView1.FindControl("TextBox10") as TextBox;
    if (newfileuploadcontrol.HasFile)
    {
       newfileuploadcontrol.SaveAs(Server.MapPath("/Cars/Copy_of_Payment_Images/") + newfileuploadcontrol.FileName);
       newtextbox.Text = "/Cars/Copy_of_Payment_Images/" + newfileuploadcontrol.FileName;
    }
 }





这个用于在同一页面中插入所有相同的值





And this for insert all the value in same page which pretty same

  protected void FormView1_ItemInserting(object sender, FormViewInsertEventArgs e)
    {

        FileUpload newfileuploadcontrol = (FileUpload)FormView1.FindControl("FileUpload1") as FileUpload;
        TextBox newtextbox = (TextBox)FormView1.FindControl("TextBox10") as TextBox;
        if (newfileuploadcontrol.HasFile)
        {
           newfileuploadcontrol.SaveAs(Server.MapPath("/Cars/Copy_of_Payment_Images/") + newfileuploadcontrol.FileName);
           newtextbox.Text = "/Cars/Copy_of_Payment_Images/" + newfileuploadcontrol.FileName;
        }
}

推荐答案

您可以尝试下面的代码 -



如果您使用AS运算符,则无需在查找控件时使用显式转换。



Could you try with below piece of code -

If you are using "AS" operator you dont need to user explicit casting while finding control.

FileUpload newfileuploadcontrol = FormView1.FindControl("FileUpload1") as FileUpload;
TextBox newtextbox = FormView1.FindControl("TextBox10") as TextBox;
           
if (newfileuploadcontrol.HasFile)
{
    string path = Server.MapPath("/Cars/Copy_of_Payment_Images/") + newfileuploadcontrol.FileName;
    newfileuploadcontrol.SaveAs(path);
    
    newtextbox.Text = path;
}


这篇关于如何将图像插入到formview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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