這是我的代碼轉換gridview到CSV。 Gridview值不是自動生成的列,它從數據庫中作爲templatefield。Gridview單元格文本爲空轉換爲CSV
try
{
DataTable dt1 = new DataTable();
Response.ClearContent();
Response.AddHeader("content-disposition", "attachment;filename=MyCsvFile.csv");
Response.ContentType = "application/text";
StringBuilder strBr = new StringBuilder();
strBr.Append("\n");
for (int j = 1; j < GridView1.Rows.Count; j++)
{
strBr.AppendLine("");
for (int k = 0; k < GridView1.HeaderRow.Cells.Count; k++)
{
strBr.Append(GridView1.Rows[j].Cells[k].Text.Replace(",", "") + ",");
}
strBr.Append("\n");
}
Response.Write(strBr.ToString());
Response.Flush();
Response.End();
}
catch (Exception ex)
{
throw ex;
}
這裏GridView1.Rows [j] .Cells [k] .Text,這個「Text」包含null值。 請幫忙...
請說明問題!發生異常?輸出的格式不符合要求? – 2015-04-06 12:01:28