Populate Gridview at runtime using textfile

后端 未结 3 671
忘了有多久
忘了有多久 2021-01-21 08:15

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

3条回答
  •  星月不相逢
    2021-01-21 08:50

    How about something like this:

        protected void readfile_Click(object sender, EventArgs e)
        {
            DataTable table = new DataTable();
            table.Columns.Add("Row No.");
            table.Columns.Add("Col No.");
            table.Columns.Add("Width");
            table.Columns.Add("Height");
            table.Columns.Add("Image URL");
            table.Columns.Add("Description");
    
            using (StreamReader sr = new StreamReader(@"D:\Temp\fileread\readtext.txt"))
            {
                while (!sr.EndOfStream)
                {
                    string[] parts = sr.ReadLine().Split(',');
                    table.Rows.Add(parts[0], parts[1], parts[2], parts[3], parts[4], parts[5]);
                }
            }
            MyGridView.DataSource = table;
            MyGridView.DataBind();
        }
    

提交回复
热议问题