如何在ASP.NET C#中的动态网格视图中上传文件 [英] How to upload file in dynamic gridview in ASP.NET C#

查看:51
本文介绍了如何在ASP.NET C#中的动态网格视图中上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

这里我有动态gridview,每行有两个下拉列表和文件上传选项。我在这里完成了所有这些。 setperviousrow,setrowdata等都成功完成,

但是对于文件上传我收到了错误。





< pre lang =C#>错误 507 ' 结算。 Accountsbootstrap.FileUpload'不包含定义 ' FileName'且没有扩展方法' FileName'接受类型的第一个参数可以找到' Billing.Accountsbootstrap.FileUpload'(您是否缺少使用指令或汇编参考?)F:\ Vijay Opticals \ Vijay Opticals \ Krishna_Opticals_old\DEMO_BillingSingle _stock \ Billing \\ \\ _Accountsbootstrap \FrameProduct.aspx.cs 233 61 结算









i得到Hasfile,FileName,SaveAs的错误。如何解决这个问题





 受保护  void  btnUpload11_Click( object  sender,EventArgs e)
{

for int vLoop = 0 ; vLoop < gvcustomerorder.Rows.Count; vLoop ++)
{
FileUpload FileU =(FileUpload)gvcustomerorder.Rows [vLoop] .FindControl(< span class =code-string> #idupload);
Image imgurl =(Image)gvcustomerorder.Rows [vLoop] .FindControl( imgurl );
标签txtkttt =(标签)gvcustomerorder.Rows [vLoop] .FindControl( imgpreview );
if (FileU.HasFile)
{

FileU.SaveAs(MapPath( 〜/ Files / + FileU.FileName));
imgurl.ImageUrl = imgurl.ImageUrl = 〜/ Files / + FileU.FileName ;
imgpreview.Text = FileU.FileName;
txtkttt.Text = imgurl.ImageUrl;
}
}
}







以上代码我用过在我的项目中。



我尝试了什么:



这里我试图添加一些参考但没有用。如果我上传一个文件而不使用动态gridview。它上传很好然后它不会上传动态控制。想要添加一些参考或我想要添加的内容。建议我。

解决方案

你有自己的名为FileUpload的类,所以.net认为你输入的是你所说的类



 FileUpload FileU =(FileUpload)gvcustomerorder.Rows [vLoop ] .FindControl( #idupload); 





如果有多个具有相同名称的类且.net使用了错误的类,则需要通过包含命名空间来完全限定类型,以确保使用正确的类;



 System.Web.UI.WebControls.FileUpload FileU =(System.Web.UI.WebControls.FileUpload)gvcustomerorder.Rows [vLoop]。 FindControl( #idupload); 

hi to all,
Here i have dynamic gridview with two dropdown and file upload option in each row . Here i done all that. setperviousrow,setrowdata, etc all done successfully,
but for file upload i got error.


Error	507	'Billing.Accountsbootstrap.FileUpload' does not contain a definition for 'FileName' and no extension method 'FileName' accepting a first argument of type 'Billing.Accountsbootstrap.FileUpload' could be found (are you missing a using directive or an assembly reference?)	F:\Vijay Opticals\Vijay Opticals\Krishna_Opticals_old\DEMO_BillingSingle _stock\Billing\Accountsbootstrap\FrameProduct.aspx.cs	233	61	Billing





i got error for Hasfile,FileName,SaveAs. How to resolve that


protected void btnUpload11_Click(object sender, EventArgs e)
      {

          for (int vLoop = 0; vLoop < gvcustomerorder.Rows.Count; vLoop++)
          {
              FileUpload FileU = (FileUpload)gvcustomerorder.Rows[vLoop].FindControl("#idupload");
              Image imgurl = (Image)gvcustomerorder.Rows[vLoop].FindControl("imgurl");
              Label txtkttt = (Label)gvcustomerorder.Rows[vLoop].FindControl("imgpreview");
              if (FileU.HasFile)
              {

                  FileU.SaveAs(MapPath("~/Files/" + FileU.FileName));
                  imgurl.ImageUrl = imgurl.ImageUrl = "~/Files/" + FileU.FileName;
                  imgpreview.Text = FileU.FileName;
                  txtkttt.Text = imgurl.ImageUrl;
              }
          }
      }




Above code i used in my project.

What I have tried:

here i tried to add some reference but no use.If i upload a single file without using dynamic gridview. it uploading fine then y it will not upload in dynamic control.Want to add some reference or what i want to add.Kindly suggest me.

解决方案

You have your own class called FileUpload so .net thinks that's the class you mean when you type

FileUpload FileU = (FileUpload)gvcustomerorder.Rows[vLoop].FindControl("#idupload");



If there are multiple classes with the same name and .net is using the wrong one you need to fully qualify the type by including the namespace to ensure the right one is used;

System.Web.UI.WebControls.FileUpload FileU = (System.Web.UI.WebControls.FileUpload)gvcustomerorder.Rows[vLoop].FindControl("#idupload");


这篇关于如何在ASP.NET C#中的动态网格视图中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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