it may seem to be simple problem to many of you, but want i am trying to do is i am reading a text file on a click event using StreamReader
(ASP.net & C#) after
Add columns to datatable using code below
DataTable dt = new DataTable();
dt.Columns.Add("Row No", typeof(Int32));
dt.Columns.Add("Col No", typeof(Int32));
dt.Columns.Add("Width", typeof(Int32));
dt.Columns.Add("Height", typeof(Int32));
dt.Columns.Add("ImageUrl", typeof(String));
dt.Columns.Add("Description", typeof(String));
And bind datatable (dt) after you populate all rows in datatable, after while loop
using (StreamReader sr = new StreamReader(@"D:\Temp\fileread\readtext.txt"))
{
while ((line = sr.ReadLine()) != null)
{
string[] parts = line.Split(',');
var dr = dt.NewRow(); //use newrow to create new row
for (int i = 0; i < parts.Length; i++)
{
dr[i] = parts[i];
}
dt.Rows.Add(dr); //add row to datatable now
}
sr.Close();
}
//bind datatable to Gridview after we load file into dt
MyGridView.DataSource = dt;
MyGridView.DataBind();