title: How to import from text file to asp.net GridView
body: <p>I'm trying to import data from text file to grid view  using the blew code :</p>
  
  <pre><code>DataTable dt = new DataTable();
  using (System.IO.TextReader tr = File.OpenText((@"d:\\My File3.log")))
  {
      string line;
      while ((line = tr.ReadLine()) != null)
      {
  
          string[] items = line.Trim().Split(' ');
          if (dt.Columns.Count == 0)
          {
              // Create the data columns for the data table based on the number of items
              // on the first line of the file
              for (int i = 0; i &lt; items.Length; i++)
                  dt.Columns.Add(new DataColumn("Column" + i, typeof(string)));
          }
          dt.Rows.Add(items);
  
      }
      //show it in gridview 
      this.GridView1.DataSource = dt;
      this.GridView1.DataBind();
  </code></pre>
  
  <p>My file is like :</p>
  
  <p>A B C</p>
  
  <p>E F D C C </p>
  
  <p>E D D D</p>
  
  <p>D P</p>
  
  <p>Then I get the following error </p>
  
  <blockquote>
    <p>Input array is longer than the number of columns in this table in c# application</p>
  </blockquote>