2012-01-18 15 views
1

私はGridViewを持っており、それを.xlsファイルにエクスポートしようとしています。このグリッドビューでページングが有効になっています。現在使用しているコードは、グリッドビューの最初のページのみをエクスポートできます。GridViewをXLSにエクスポート---ページングの問題

Response.Clear(); 
    Response.Buffer = true; 

    Response.AddHeader("content-disposition","attachment;filename=DataTable.xls"); 
    Response.Charset = ""; 
    Response.ContentType = "application/vnd.ms-excel"; 

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

    //As you notice, below I tried to disable the paging yet it's unsuccessful 
    //FYI I am able to really prevent first column, header row, and footer row to 
    //be exported through this 

    gvGridView.Columns[0].Visible = false; 
    gvGridView.HeaderRow.Visible = false; 
    gvGridView.FooterRow.Visible = false; 
    gvGridView.AllowPaging = false; 

    for (int i = 0; i < gvGridView.Rows.Count; i++) 
    { 
     gvGridView.Rows[i].Attributes.Add("class", "textmode"); 
    } 
    gvGridView.RenderControl(hw); 

    string style = @"<style> .textmode { mso-number-format:\@; } </style>"; 
    Response.Write(style); 
    Response.Output.Write(sw.ToString()); 
    Response.Flush(); 
    Response.End(); 

この質問に回答しましたが、正解はありませんでした。

何か助けていただければ幸いです。

感謝の

答えて

1

あなたはエクスポートし、その後、gvGridView.AllowPaging = false;を指定後にGridViewを再バインドする必要があります。そうでない場合、.RenderControl(hw);は現在選択されているGridViewページのみをレンダリングします。

+0

これは機能しています。私はそれも考えていたはずです。ありがとうの – rofans91

+0

私はそれがまだ働いていることに気づいた。それは、以前に無効にした、私の最初の列、見出し行、フッター行を何らかの形でエクスポートしています。 – rofans91

+0

私はこの問題を自分で解決しました。 Thx – rofans91

1

AllowPagingプロパティを変更した後、GridView.DataBind()を作成するだけです。