使用asp.net从gridview控件下载文件 [英] Download file from gridview control using asp.net

查看:67
本文介绍了使用asp.net从gridview控件下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



使用asp.net从gridview控件下载word文件?

这里有小错误请点击下面请检查请回复我



源代码:

<前lang =c#> 受保护 void Page_Load( object sender,EventArgs e)
{
格();
}

private void grid()
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings [ ConnectionString的]的ConnectionString)。
string query = 选择姓名,照片来自ImageUpdate;
SqlDataAdapter da = new SqlDataAdapter(query,con);
DataTable table = new DataTable();
da.Fill(table);
GridView1.DataSource = table;
GridView1.DataBind();

}
protected void GridView1_SelectedIndexChanged( object sender,EventArgs e)
{
string filename = 选择姓名,照片来自ImageUpdate,其中Email = @ Email;
Response.ContentType = application / octet-stream;
Response.AppendHeader( Content-Disposition attachment; filename = + filename);
string aaa = Server.MapPath( 〜/ ProductImage / + filename);
Response.TransmitFile(Server.MapPath( 〜/ ProductImage / + filename)) ;
Response.End();
}

解决方案

下面链接提供上传和下载文件到gridview你只能参考下载部分



上传和下载文件 [ ^ ]


Dear All,

Download word file from gridview control using asp.net?
here small error is coming in below please check and reply me please

source code:

protected void Page_Load(object sender, EventArgs e)
{
grid();
  }

private void grid()
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString);
        string query = "select Name,Photo from ImageUpdate";
        SqlDataAdapter da = new SqlDataAdapter(query, con);
        DataTable table = new DataTable();
        da.Fill(table);
        GridView1.DataSource = table;
        GridView1.DataBind();

    }
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
string filename = "select Name,Photo from ImageUpdate where Email=@Email";
Response.ContentType = "application/octet-stream";
Response.AppendHeader("Content-Disposition", "attachment;filename=" + filename);
string aaa = Server.MapPath("~/ProductImage/" + filename);
Response.TransmitFile(Server.MapPath("~/ProductImage/" + filename));
Response.End();
}

解决方案

Below link gives upload and download file to gridview you can refer only download part

Upload and download file[^]


这篇关于使用asp.net从gridview控件下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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