asp.net怎么调用另存功能

解决方案 »

  1.   

    分情况 导出的时候就有类似弹出路径选择的对话框GridView   tmpGv   =   new   GridView(); 
                            DataSet   ds   =   new   DataSet(); 
                            SqlDataAdapter   da   =   new   SqlDataAdapter(cmd); 
                            da.Fill(ds,   "TitleName "); 
                            tmpGv.DataSource   =   ds; 
                            tmpGv.DataMember   =   "TitleName "; 
                            tmpGv.DataBind(); 
                            ToExcel(tmpGv,   "Daily "); 
    ////// 
    public   void   ToExcel(System.Web.UI.Control   ctl,   string   FileName) 
            { 
                    HttpContext.Current.Response.Charset   =   "UTF-8 ";//UTF-8 
                    HttpContext.Current.Response.ContentEncoding   =   System.Text.Encoding.Default; 
                    HttpContext.Current.Response.ContentType   =   "application/ms-excel "; 
                    HttpContext.Current.Response.AppendHeader( "Content-Disposition ",   "attachment;filename= "   +   " "   +   FileName   +   ".xls "); 
                    //ctl.Page.EnableViewState   =   true; 
                    System.IO.StringWriter   tw   =   new   System.IO.StringWriter(); 
                    HtmlTextWriter   hw   =   new   HtmlTextWriter(tw); 
                    ctl.RenderControl(hw); 
                    HttpContext.Current.Response.Write(tw.ToString()); 
                    HttpContext.Current.Response.End(); 
            }   
      

  2.   

    先弹出保存对话框,
    public void ToExcel(System.Web.UI.Control ctl, string FileName) 
      { 
      HttpContext.Current.Response.Charset = "UTF-8 ";//UTF-8 
      HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.Default; 
      HttpContext.Current.Response.ContentType = "application/ms-excel "; 
      HttpContext.Current.Response.AppendHeader( "Content-Disposition ", "attachment;filename= " + " " + FileName + ".xls "); 
      //ctl.Page.EnableViewState = true; 
      System.IO.StringWriter tw = new System.IO.StringWriter(); 
      HtmlTextWriter hw = new HtmlTextWriter(tw); 
      ctl.RenderControl(hw); 
      HttpContext.Current.Response.Write(tw.ToString()); 
      HttpContext.Current.Response.End(); 
      }   
    引用一下楼上的