I have this loop, which I am using to get the values of all cells within all rows of a gridview and then write it to a csv file. My loop looks like this:
string filename = @"C:\Users\gurdip.sira\Documents\Visual Studio 2008\WebSites\Supressions\APP_DATA\surpressionstest.csv";
StreamWriter sWriter = new StreamWriter(filename);
string Str = string.Empty;
string headertext = "";
sWriter.WriteLine(headertext);
for (int i = 0; i <= (this.GridView3.Rows.Count - 1); i++)
{
for (int j = 0; j <= (this.GridView3.Columns.Count - 1); j++)
{
Str = this.GridView3.Rows[i].Cells[j].Text.ToString();
sWriter.Write(Str);
}
sWriter.WriteLine();
}
sWriter.Close();
The problem with this code is that, when stepping through, the 2nd loop (the one going through the columns) does not begin as the debugger does not hit this loop and thus my file is empty.
Any ideas on what is causing this? The code itself looks fine.
Thanks