title: Populate Gridview at runtime using textfile
body: <p>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 <code>StreamReader</code> (ASP.net &amp; C#) after reading that text file i am splitting each line with ',' delimiter and then each part of it i am storing in <code>Datatable's</code> column and then binding the datatable to my gridview, my problem is i have written the code but i m getting empty gridview like this</p>
  
  <p><img src="https://i.stack.imgur.com/Zumt4.png" alt="enter image description here"><br>
  Gridviews Column header i have created from designer with <code>autogeneratecolumns="false"</code></p>
  
  <p>my code is</p>
  
  <pre><code>protected void readfile_Click(object sender, EventArgs e)
  {
      string line;
      DataTable dt = new DataTable();
      using (StreamReader sr = new StreamReader(@"D:\Temp\fileread\readtext.txt"))
      {
          while ((line = sr.ReadLine()) != null)
          {
              string[] parts = line.Split(',');
              dt.Rows.Add();
              for (int i = 0; i &lt; parts.Length; i++)
              {
                  dt.Columns.Add();
                  dt.Rows[0][i] = parts[i];
                  MyGridView.DataSource = dt;
                  MyGridView.DataBind();
              }
          }
          sr.Close();
      }
  </code></pre>
  
  <p>my text file has data </p>
  
  <pre><code>1,1,4,2,"#",Description1
  5,5,4,2,"#",Description2
  3,3,6,3,"#",Description3
  2,2,4,2,"#",Description4
  4,5,4,2,"#",Description5
  </code></pre>
  
  <p>Hope you got it what i am trying to ask.</p>