Can anybody help me understand what these lines of codes really means...i understand it but not exactly...i mean what foreach is exactly doing here???
if (dt.Rows.Count > 0)
{
//GridView1.Visible = true;
Gridview1.DataSource = dt;
Gridview1.DataBind();
StringBuilder sb = new StringBuilder();
foreach (DataColumn col in dt.Columns)
{
sb.Append(col.ColumnName + ",");
}
sb.Remove(sb.Length - 1, 1);
sb.Append(Environment.NewLine);
foreach (DataRow row in dt.Rows)
{
for (int i = 0; i < dt.Columns.Count; i++)
{
sb.Append(row[i].ToString() + ",");
}
sb.Append(Environment.NewLine);
}
Response.ClearHeaders();
Response.AppendHeader("Content-Disposition", "attachment; filename=CDR OF " + TextBox1.Text + ".csv");
Response.AppendHeader("Content-Length", sb.Length.ToString());
Response.ContentType = "text/csv";
Response.Write(sb.ToString());
Response.Flush();
Response.End();
}
else
{
//GridView1.Visible = false;
Show("No CDR Found!");
}
And can we use StringWriter or string in place of StringBuilder ???