zoukankan      html  css  js  c++  java
  • gridview按钮列的下载功能

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
           
    //这里是模板列里面的按钮,需要设置CommandArgument ="<%# GridView1.Rows.Count %>",否则出错
            if (e.CommandName == "Download")
            {
                FileDownload(
    @"F:\music\6-渴望.mp3");
            }
        }

       
    private void FileDownload(string FullFileName)
        {
            FileInfo DownloadFile
    = new FileInfo(FullFileName);
            Response.Clear();
            Response.ClearContent();
            Response.ClearHeaders();
            Response.Buffer
    = false;
            Response.ContentType
    = "application/octet-stream";
            Response.AppendHeader(
    "Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(DownloadFile.FullName, System.Text.Encoding.UTF8));
            Response.AppendHeader(
    "Content-Length", DownloadFile.Length.ToString());
            Response.AddHeader(
    "Content-Transfer-Encoding", "binary");
            Response.ContentEncoding
    = System.Text.Encoding.GetEncoding("UTF-8");
            Response.WriteFile(DownloadFile.FullName);
            Response.Flush();
            Response.End();
        }

    注意:

      如果是在GridView在UpdatePanel下,就需要加入如下代码:

      <Triggers>
         
    <asp:PostBackTrigger ControlID="GridView1" />
      </Triggers>

      否则会报错

     

  • 相关阅读:
    POJ 1873 计算几何
    POJ 1584 计算几何
    POJ 1410 计算几何
    BZOJ 1208 set
    BZOJ 1503 splay
    BZOJ 5277 IQ题orz
    Codeforces Round #549 (Div. 2)A. The Doors
    (原创)同余定理
    April Fools Day Contest 2019 A. Thanos Sort
    PTA数据结构之 List Leaves
  • 原文地址:https://www.cnblogs.com/tianguook/p/1874130.html
Copyright © 2011-2022 走看看