2011-12-20 4 views
0

私は製品カテゴリと製品カタログのように機能する2つのgridviewを持っています。 各カテゴリには少数の製品があります。 選択した製品カテゴリ:「フルーツ」 カタログがある:「アップル、ユーザーがカテゴリを選択し、製品カタログを閲覧した後2グリッドビューをExcelにエクスポート

今、私はこの2

Excelで例を輸出したいと思いますバナナ、オレンジ "

商品カテゴリとカタログを保存します。製品カタログのリストをエクスポートして、今、私は唯一のことについては

。(1つのGridViewの簡単なエクスポートはExcelへ)

私は自分自身を明確に願っています。ボタンをクリックしたときに、#

currenctコードはたぶん、あなたは

string filename = String.Format("Survey Results_{0}_{1}.xls", 
    DateTime.Today.Month.ToString(), DateTime.Today.Year.ToString()); 

    Response.Clear(); 
    Response.AddHeader("Content-Disposition", "attachment;filename=" + filename); 
    Response.Charset = ""; 

    // SetCacheability doesn't seem to make a difference (see update) 
    Response.Cache.SetCacheability(System.Web.HttpCacheability.NoCache); 

    Response.ContentType = "application/vnd.xls"; 

    System.IO.StringWriter stringWriter = new System.IO.StringWriter(); 
    System.Web.UI.HtmlTextWriter htmlWriter = new HtmlTextWriter(stringWriter); 

    // Replace all gridview controls with literals 
    ClearControls(GridView2); 

    // Throws exception: Control 'ComputerGrid' of type 'GridView' 
    // must be placed inside a form tag with runat=server. 
    // ComputerGrid.RenderControl(htmlWrite); 

    // Alternate to ComputerGrid.RenderControl above 
    System.Web.UI.HtmlControls.HtmlForm form 
     = new System.Web.UI.HtmlControls.HtmlForm(); 
    Controls.Add(form); 

    form.Controls.Add(GridView2); 
    form.RenderControl(htmlWriter); 

    Response.Write(stringWriter.ToString()); 
    Response.End(); 
+0

自分で解決しました。私は、選択された「製品カテゴリー」としてExcelファイル名を持つソリューションを考え出します。 –

答えて

0

結果を結合してcodebehindでダイナミックgridviewを構築し、代わりのgridview2を出力してみることができますがC asp.net上で実行されている

イム動的に生成されたgridviewをエクスポートする必要があります。

+0

hmmm ..私はそれが達成できるとは思っていません。私は選択した '商品カテゴリ'を '商品カタログ'の前に表示したいだけです。ありがとう –

関連する問題