显示上传的文件数据到gridview [英] display uploaded file dat into gridview

查看:83
本文介绍了显示上传的文件数据到gridview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用带vb.net的asp.net将上载的文件(任何)数据显示到gridview中,我该怎么做呢?请帮助我

i want to display the uploaded file(any) data into gridview using asp.net with vb.net how can i do this please help me

推荐答案

嗨 表单发布后,您可以通过文件上传控件的属性访问上传的文件详细信息
1)添加一个gridview,按钮,文件上传控件和一个对象数据源.
2)创建两个如下所示的类
Hi Once the form posted, you can access the uploaded files details though the file upload control''s properties
1) Add a gridview, button, file upload control and a object datasource.
2) Create two classes as shown below
public class FileDetail
{
    public string Name { get; set; }
    public string Type { get; set; }
    public int Length { get; set; }
}


public static class FileDetailCollection
{
    public static IList<FileDetail> FileList =new List<FileDetail>();
    public static IList<FileDetail> GetAll()
    {
        return FileList;
    }
}


3)使用FileCollection对象和select方法将Objectdatasource配置为GetAll
4)将Gridview的数据源(在我的前言gridview4中)设置为创建的对象数据源
5)在按钮的单击事件(表单提交)中,具有以下代码


3) Configure the objectdatasource with the FileCollection object and the select method as GetAll
4)Set Gridview''s (in my examble gridview4) datasource to the object data source created
5) In the button''s click event (form submission) have the following code

HttpPostedFile postedFile= FileUpload1.PostedFile;
FileDetail fDetail = new FileDetail();
fDetail.Length = postedFile.ContentLength;
fDetail.Name = postedFile.FileName;
fDetail.Type = postedFile.ContentType;
FileDetailCollection.FileList.Add(fDetail);
GridView4.DataBind();


这篇关于显示上传的文件数据到gridview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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