title: I need to get the value of a drop down list in an asp gridview when updating the row
body: <p>Everything should work, but i can't figure out why i can't get the value from the ddl. I know the code is not too clean.</p>
  
  <pre><code>protected void gridProduse_RowEditing(object sender, GridViewEditEventArgs e)
      {
          gridProduse.EditIndex = e.NewEditIndex;
          gridProduse.DataBind();
  
  
          using (var context = new SATContext())
          {
              var query = from t in context.TipuriProduse
                          select t.Denumire;
              DropDownList list = new DropDownList();
              list.DataSource = query.ToList();
              list.DataBind();
              list.ID = "ddlTipProdus";
              list.Height = 27;
              DropDownList listMoneda = new DropDownList();
              listMoneda.ID = "ddlMoneda";
              listMoneda.Items.Add("RON");
              listMoneda.Items.Add("EUR");
              listMoneda.Items.Add("USD");
              listMoneda.Height = 27;
              gridProduse.Rows[e.NewEditIndex].Cells[7].Controls.Add(list);
              gridProduse.Rows[e.NewEditIndex].Cells[6].Controls.Add(listMoneda);
              gridProduse.Rows[e.NewEditIndex].Cells[6].Controls[0].Visible = false;
              gridProduse.Rows[e.NewEditIndex].Cells[7].Controls[0].Visible = false;
          }
      }
  
      protected void gridProduse_RowUpdating(object sender, GridViewUpdateEventArgs e)
      {
          GridViewRow row = gridProduse.Rows[e.RowIndex];
          Produs prod = new Produs();
          prod.ProdusId = Convert.ToInt32(((TextBox)(row.Cells[2].Controls[0])).Text);
          prod.Denumire = ((TextBox)(row.Cells[3].Controls[0])).Text;
  
          DropDownList ddl = (DropDownList)gridProduse.Rows[e.RowIndex].FindControl("ddlMoneda");
          prod.Moneda = ddl.SelectedValue; // this is where i get the error
          //prod.Moneda = ((row.FindControl("ddlMoneda") as DropDownList)).SelectedValue;
          prod.PretCuTVA = Convert.ToInt32(((TextBox)(row.Cells[5].Controls[0])).Text);
          prod.PretFaraTVA = Convert.ToInt32 (((TextBox)(row.Cells[4].Controls[0])).Text);
          lit1.Text = prod.ProdusId.ToString();
          using (var context = new SATContext())
          {
              IRepository&lt;Produs&gt; ProdusRepository = new ProdusRepository();
              ProdusRepository.Update(prod);
          }
          gridProduse.EditIndex = -1;
          gridProduse.DataBind();
  
          Response.Redirect("Produse.aspx");
      }
  </code></pre>
  
  <p>And this is the error:</p>
  
  <p>An exception of type 'System.NullReferenceException' occurred in Licenta.dll but was not handled in user code</p>
  
  <p>Additional information: Object reference not set to an instance of an object.</p>