title: Access gridview rows after postback
body: <p>Good day!</p>
  
  <p>I need to dynamycally upload files and display information in gridview.
  After file upload, i need to select file type in dropdown. 
  But after postback i can't access Gridview1 rows, and get selected file types. After postback Gridview1.Rows.Count = 0.</p>
  
  <p>Is it possible to get selected values from DropDownLists?</p>
  
  <pre><code>&lt;asp:GridView ID="GridView1"  runat="server" ShowHeader="False" AutoGenerateColumns="false"&gt;
  &lt;Columns&gt;
  &lt;asp:BoundField DataField="FileName" /&gt;
  &lt;asp:TemplateField HeaderText="FileType"&gt;
  &lt;ItemTemplate&gt;
  &lt;asp:DropDownList runat="server"&gt;
  &lt;asp:ListItem Value="Val1"&gt;Val1&lt;/asp:ListItem&gt;
  &lt;asp:ListItem Value="Val2"&gt;Val2&lt;/asp:ListItem&gt;
  &lt;asp:ListItem Value="Val3"&gt;Val3&lt;/asp:ListItem&gt;
  &lt;/asp:DropDownList&gt;
  &lt;/ItemTemplate&gt;
  &lt;/asp:TemplateField&gt;
  &lt;asp:CommandField DeleteText="Remove" ShowDeleteButton="true" /&gt;
  &lt;/Columns&gt;
  &lt;/asp:GridView&gt;
  
  &lt;asp:FileUpload ID="FileUpload" runat="server" onchange="this.form.submit()" /&gt;
  </code></pre>
  
  <p>Thanks</p>
  
  <p>In Page_Load, during PostBack, GridView rows is empty.</p>
  
  <pre><code>protected void Page_Load(object sender, EventArgs e)
  {
       RestoreForm();
  
       if (IsPostBack &amp;&amp; FileUpload.HasFile)
       {
           AddRow(FileUpload.PostedFile.FileName);
       }
  
       FilesGridView.RowDeleting += new GridViewDeleteEventHandler(RemoveFileFromTable);
  }
  
  private void AddRow(string file)
  {
       DataTable dt = (DataTable)Page.Session["Files"];
       if (dt == null)
       {
          AddDataTableToSession();
          dt = (DataTable)Page.Session["Files"];
       }
       DataRow dr = dt.NewRow();
       dr["FileName"] = file;
       dr["FileType"] = 0;
       dt.Rows.Add(dr);
       Page.Session["Files"] = dt;
       FilesGridView.DataSource = dt;
       FilesGridView.DataBind();
   }
  
   private void AddDataTableToSession()
   {
       DataTable dt = new DataTable("Files");
       DataColumn dc = new DataColumn("FileName", Type.GetType("System.String"));
       dt.Columns.Add(dc);
       dc = new DataColumn("FileType", Type.GetType("System.String"));
       dt.Columns.Add(dc);
       Page.Session["Files"] = dt;
   }
  
   private void RemoveFileFromTable(object sender, GridViewDeleteEventArgs e)
   {
       int recordToDelete = e.RowIndex;
       DataTable dt = (DataTable)Page.Session["Files"];
       int cn = dt.Rows.Count;
       dt.Rows.RemoveAt(recordToDelete);
       dt.AcceptChanges();
       Page.Session["Files"] = dt;
       FilesGridView.DataSource = dt;
       FilesGridView.DataBind();
   }
  </code></pre>