请教在gridview里面的imagebutton按钮左击后弹出下载对话框(既实现下载功能)
时间:2011-12-21
来源:互联网
这是我的代码:
protected void imgbtnDF_Click(object sender, ImageClickEventArgs e)
{
SqlConnection myConn = new SqlConnection("server=(local); database=cycps; uid=sa; pwd=;");
myConn.Open();
//获取imgbtnDelete的ImageButton对象
ImageButton imgbtn = (ImageButton)sender;
//引用imgbtnDelete控件的父控件上一级控件
GridViewRow gvr = (GridViewRow)imgbtn.Parent.Parent;
//获取文件真实姓名
string sqlStr = "select dname from [don] where did='" + GridView1.DataKeys[gvr.RowIndex].Value.ToString() + "'";
DataSet ds = new DataSet();
//获取文件路径
string strFilePath = Server.MapPath("Don//" + Request.QueryString["dname"]);
ds.Dispose();
myConn.Close();
if (File.Exists(strFilePath))
{
System.IO.FileInfo file = new System.IO.FileInfo(strFilePath);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = true;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(file.Name));
Response.AppendHeader("Content-Length", file.Length.ToString());
Response.WriteFile(file.FullName);
Response.Flush();
Response.End();
}
数据库表里面就只有id和name信息,我一直在想我点了那个下载按钮后,怎么把值传啊?是不是这句错了??
string sqlStr = "select dname from [don] where did='" + GridView1.DataKeys[gvr.RowIndex].Value.ToString() + "'";
string strFilePath = Server.MapPath("Don//" + Request.QueryString["dname"]);
这句也有问题对不对??
该怎么做啊。大虾教我啊 我初学。。。
protected void imgbtnDF_Click(object sender, ImageClickEventArgs e)
{
SqlConnection myConn = new SqlConnection("server=(local); database=cycps; uid=sa; pwd=;");
myConn.Open();
//获取imgbtnDelete的ImageButton对象
ImageButton imgbtn = (ImageButton)sender;
//引用imgbtnDelete控件的父控件上一级控件
GridViewRow gvr = (GridViewRow)imgbtn.Parent.Parent;
//获取文件真实姓名
string sqlStr = "select dname from [don] where did='" + GridView1.DataKeys[gvr.RowIndex].Value.ToString() + "'";
DataSet ds = new DataSet();
//获取文件路径
string strFilePath = Server.MapPath("Don//" + Request.QueryString["dname"]);
ds.Dispose();
myConn.Close();
if (File.Exists(strFilePath))
{
System.IO.FileInfo file = new System.IO.FileInfo(strFilePath);
Response.Clear();
Response.ClearHeaders();
Response.Buffer = true;
Response.ContentType = "application/octet-stream";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(file.Name));
Response.AppendHeader("Content-Length", file.Length.ToString());
Response.WriteFile(file.FullName);
Response.Flush();
Response.End();
}
数据库表里面就只有id和name信息,我一直在想我点了那个下载按钮后,怎么把值传啊?是不是这句错了??
string sqlStr = "select dname from [don] where did='" + GridView1.DataKeys[gvr.RowIndex].Value.ToString() + "'";
string strFilePath = Server.MapPath("Don//" + Request.QueryString["dname"]);
这句也有问题对不对??
该怎么做啊。大虾教我啊 我初学。。。
作者: madenameduo 发布时间: 2011-12-21
在线等啊 着急死了。。
作者: madenameduo 发布时间: 2011-12-21
你可以直接把文件路径存数据库啊,绑定时直接绑定到gridview嘛
作者: lovelcl 发布时间: 2011-12-21
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28