net在gridview中上传文件

net在gridview中上传文件

本文介绍了使用asp.net和vb.net在gridview中上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我需要使用asp.net和vb.net上传文件的代码:

功能:在网格外部,当我们单击
时,有一个名为附加"的按钮.文件应浏览的按钮,然后应显示所选文件
在gridview中.


这是我的代码:

Hi,

I need a code for file upload using asp.net and vb.net:

functionality: outside the grid we have a button called Attach, when we click
the button the files should browse and then selected file should be display
in gridview.


Here is my code :

<script type="text/javascript">
function BrowseFile()
{
    var fileUpload = document.getElementById("<%=FileUpload1.ClientID %>");
    var listBox = document.getElementById("<%=lbFileNames.ClientID %>");
    fileUpload.click();
    var filePath = fileUpload.value;
    var j = listBox.options.length;
    listBox.options[j]=new Option();
    listBox.options[j].text=filePath.substr(filePath.lastIndexOf("\\")+1);
    listBox.options[j].value=filePath;
}
</script>









<asp:FileUpload ID="FileUpload1" runat="server" style="display:none" />
 <asp:ListBox ID="ListBox1" runat="server" Width="292px"></asp:ListBox>
    <input id="Button3" type="button" value="Attach" onclick="BrowseFile()"/>




错误:如果列表框放置在gridview的itemtemplate中
然后在脚本中面临错误的列表框未声明

使用此代码,我们可以上传文件并显示在列表框中,但我想
在网格视图中显示.请帮帮我.
在此先感谢




Error : if the listbox is placed in itemtemplate of gridview
then in script im facing error listbox is not declared

With this code we can upload file and display in a listbox but i want to
display in grid view. please help me.
thanks in advance

推荐答案

outside the grid we have a button called Attach, when we click
the button the files should browse and then selected file should be display
in gridview.



您是说它是某种文本文件,需要显示其内容还是仅显示文件名?

更新:(继续下面的讨论)
列表框用于列出某些项目,或显示多个项目值.将其放入GridView时,将具有多个列表框.因此,即使您具有多个文件上载控件,一个列表框也足以显示已浏览文件的名称.此外,GridView是一个数据绑定控件,并假定已绑定到数据源.
因此恕我直言,您的设计是错误的.

但是,如果您仍然想继续做下去,并且考虑到只有一行,并且GridView内有一个列表框,而外面有多个文件上载控件,则可以使用firebug之类的工具,或者只是在浏览器中查看页面源代码来查找列出列表框控件的呈现ID,并在JavaScript中使用它.

如果您可以更好地说明您的情况,我将尽力帮助您实现.

干杯,
安库尔



Do you mean it is some kind of text file and you need to display it''s content or just the file name?

UPDATE: (in continuation to our discussion below)
List box is meant to list down some items or in other words display multiple item values. When you put it inside GridView, you have multiple listboxes. So even if you have multiple file upload controls, one listbox is enough to show the names of the browsed files. Moreover, GridView is a data bound control and is suppose to be bound to a datasource.
Thus IMHO, your design is wrong.

But if you still want to continue the way you are doing and considering you have only one row with a list box inside a GridView and multiple file upload controls outside it, use tool like firebug or just view source of the page in the browser to find out the rendered id of the listbox control and use that in your JavaScript.

If you could explain your scenario better, I shall try to help you implement it.

Cheers,
Ankur


这篇关于使用asp.net和vb.net在gridview中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 22:58