2016-07-09 10 views
0

companyというドロップダウンとexport to excelというボタンとグリッドビューがありますが、両方のコントロールの更新パネルがありますが、Excelをエクスポートするとドロップダウンがもう機能しません。ページ。ファイルをExcelにエクスポートした後、ドロップダウンが機能しません。

マイ輸出コード:

protected void Button1_Click(object sender, EventArgs e) 
    { 

     // HttpContext.Current.Response.Clear(); 
     HttpContext.Current.Response.AddHeader(
      "content-disposition", string.Format("attachment; filename={0}", "Kontratat-" + DateTime.Now.ToShortDateString() + ".xls")); 
     HttpContext.Current.Response.ContentType = "application/vnd.ms-excel"; 


     StringWriter sw = new StringWriter(); 
     HtmlTextWriter hw = new HtmlTextWriter(sw); 


     HtmlForm frm = new HtmlForm(); 
     hw.WriteLine("<center><b><u><font size='5'>Kontratat</font></u></b></center>");//will be displayed in excel as a heading. 
     GridView1.Parent.Controls.Add(frm); 
     frm.Controls.Add(GridView1); 
     frm.RenderControl(hw); 
     HttpContext.Current.Response.Write(sw.ToString()); 
     HttpContext.Current.Response.Flush(); 
     HttpContext.Current.Response.End(); 

    }    

と私のaspxコード

<asp:UpdatePanel ID="UpdatePanel1" runat="server"> 
<Triggers> 
    <asp:AsyncPostBackTrigger ControlID="DropDownList1" EventName="SelectedIndexChanged" /> 
    <asp:PostBackTrigger ControlID="Button1" /> 
</Triggers> 
<ContentTemplate> 
    <asp:GridView ID="GridView1" runat="server" BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px" CellPadding="4" CellSpacing="2" ForeColor="Black"> 
    </asp:GridView> 
</ContentTemplate> 

は、私は、レンダリングすべきコードでXLSファイルを返すと思います

+0

なぜこれをASP.NET MVCとしてタグ付けしましたか? – mason

答えて

0

私を助けてください更新パネルの内容は良い解決策ではありません。なぜボタンのコードを含む新しいページにリダイレクトしないのですか?page_loadをクリックしますか?このようにして、新しいページ全体がファイルを生成し、ブラウザは保存するように要求し、自動的にプリンシパルページにリダイレクトします。あなたはその方法を試すことができますか?

関連する問題