code_junkie

Writing gridview to file does not work with nested for loop

Nov 11th, 2011
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. string filename = @"C:Usersgurdip.siraDocumentsVisual Studio 2008WebSitesSupressionsAPP_DATAsurpressionstest.csv";
  2. StreamWriter sWriter = new StreamWriter(filename);
  3. string Str = string.Empty;
  4.  
  5. string headertext = "";
  6.  
  7. sWriter.WriteLine(headertext);
  8.  
  9. for (int i = 0; i <= (this.GridView3.Rows.Count - 1); i++)
  10. {
  11. for (int j = 0; j <= (this.GridView3.Columns.Count - 1); j++)
  12. {
  13. Str = this.GridView3.Rows[i].Cells[j].Text.ToString();
  14. sWriter.Write(Str);
  15. }
  16.  
  17. sWriter.WriteLine();
  18.  
  19. }
  20.  
  21. sWriter.Close();
  22.  
  23. for (int i = 0; i <= (this.GridView3.Rows.Count - 1); i++)
  24. {
  25.  
  26. for (int j = 0; j <= (this.GridView3.Rows[i].Cells.Count - 1); j++)
  27. {
  28.  
  29. Str = this.GridView3.Rows[i].Cells[j].Text.ToString();
  30.  
  31.  
  32. sWriter.Write(Str);
  33. }
  34. }
  35.  
  36. string filename = @"C:Usersgurdip.siraDocumentsVisual Studio 2008WebSitesSupressionsAPP_DATAsurpressionstest.csv";//1
  37. StreamWriter sWriter = new StreamWriter(filename);//2
  38. string Str = string.Empty;//3
  39. string headertext = ""; //4
  40. sWriter.WriteLine(headertext); //5
  41. for (int i = 0; i <= (this.GridView3.Rows.Count - 1); i++) //6
  42. { //7
  43. for (int j = 0; j <= (this.GridView3.Columns.Count - 1); j++) //8
  44. { //9
  45. Str = this.GridView3.Rows[i].Cells[j].Text.ToString();//10
  46. sWriter.Write(Str);//11
  47. }//12
  48. sWriter.WriteLine();//13
  49. }//14
  50. sWriter.Close();//15
  51. }//16
Add Comment
Please, Sign In to add comment