用gridview显示文件信息列表,文件字段有 编号,版块名称,名称,大小,上传时间,上传人,保存路径,角色,想通过点击下载按钮获得路径进行下载,前面有定义 gvInfo.DataKeyNames = new string[] { "编号" }; 这里 编号 和 保存路径 没在gridview显示。
protected void gvInfo_RowCommand(object sender, GridViewCommandEventArgs e)//下载
{
if (e.CommandName == "download")
{ if (Session["Name"] == null)
{
Response.Write("<script language=javascript>alert('请先注册登录再下载!')</script>");
return;
}
else
{
//这里怎么改?????
filemanage.FileID = gvInfo.SelectedDataKey.Value.ToString();
DataSet ds= filemanage.FindFileByID(filemanage,"tb_File");
string filename = ds.Tables[0].Rows[0][2].ToString(); //下载方式
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename));//下载保存文件名
string filepath = Server.MapPath(ds.Tables[0].Rows[0][6].ToString());
Response.TransmitFile(filepath);
}
}
}
新手,麻烦高手来解答下,谢谢
protected void gvInfo_RowCommand(object sender, GridViewCommandEventArgs e)//下载
{
if (e.CommandName == "download")
{ if (Session["Name"] == null)
{
Response.Write("<script language=javascript>alert('请先注册登录再下载!')</script>");
return;
}
else
{
//这里怎么改?????
filemanage.FileID = gvInfo.SelectedDataKey.Value.ToString();
DataSet ds= filemanage.FindFileByID(filemanage,"tb_File");
string filename = ds.Tables[0].Rows[0][2].ToString(); //下载方式
Response.ContentType = "application/x-zip-compressed";
Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(filename));//下载保存文件名
string filepath = Server.MapPath(ds.Tables[0].Rows[0][6].ToString());
Response.TransmitFile(filepath);
}
}
}
新手,麻烦高手来解答下,谢谢
我还是调出 编号列,改为
filemanage.FileID = gvInfo.Rows[Convert.ToInt32(e.CommandArgument)].Cells[0].Text;
得了,
还是谢谢各位!!