Try it this way,
DataTable dt = new DataTable();
dt.Columns.Add("TextFiles");
string[] files = Directory.GetFiles("E:\\DOTNET APPLICATIONS\\Asp.net\\TextfilestoGrid\\TextFolder\\");
foreach (string file in files)
{
string str = IO.File.ReadAllText(file);
DataRow dr = dt.NewRow();
dr["TextFiles"] = str;
dt.Rows.Add(dr);
}
GV.DataSource = dt;
GV.DataBind();
You are creating new datatable in each iteration and binding your grid to it, which is not correct approach. Moreover,
IO.File.ReadAllText
is a good approach to read the text content from file.