2017-03-27 5 views
0
GridView grdExgratia = new GridView(); 
DataSet ds = (DataSet)Session["DataSet"]; 

try 
{ 
    if (ds != null && ds.Tables[0].Rows.Count > 0) 
    { 
     grdExgratia.DataSource = ds; 
     grdExgratia.DataBind(); 

     for (int i = 0; i < grdExgratia.Rows.Count; i++) 
     { 
      DataGridItem dataItem = dgExgratia.Items[i]; 
      CheckBox chkApprove = (CheckBox)dataItem.FindControl("chkApprove"); 
      Label lblB_FLAG = (Label)dataItem.FindControl("lblB_FLAG"); 

      if (chkApprove.Enabled== true) 
      { 
       lblB_FLAG.Text = "Paid"; 
      } 
      else 
      { 
      } 
     } 

     Response.Clear(); 
     Response.Buffer = true; 
     Response.ClearContent(); 
     Response.ClearHeaders(); 
     StringWriter strwritter = new StringWriter(); 
     HtmlTextWriter htmltextwrtter = new HtmlTextWriter(strwritter); 
     Response.ContentType = "application/vnd.ms-excel"; 
     Response.AddHeader("Content-Disposition", "attachment;filename= Exgratia_Employees.xls"); 
     grdExgratia.RenderControl(htmltextwrtter); 
     Response.Write(strwritter.ToString()); 
     Response.End(); 
    } 
} 

上記は私がエクスポートするために使用しているコードです。しかし、データをエクスポートする間、最後の列はBITのB_FLAGで、データベースのデータ型はチェックボックスに変換されます。グリッドビューでデータを表示している間、TRUEとFALSEとしてレンダリングされます。いずれかがチェックボックスの代わりにExcelにテキスト値をエクスポートするのを助けてください。excelにエクスポートすると、文字列ではなくExcelのチェックボックスがエクスポートされます

+0

あなたのコントロールの名前を確認してください。 –

+0

@redsまだ動作していないことを確認しました。他の方法をお勧めしますか? – Shardul

+0

あなたのStringWriter strwritterはforループとは関係がありません。StringBuilderもありません。 –

答えて

0

これをtrueまたはfalseにするには、グリッドをExcelにレンダリングするので、データソースを取得してデータを操作する必要があります。たとえば、 "chkApprove"ブール値に基づいて "true"と "false"の新しい行を追加してからエクスポートします。

関連する問題