title: ObjectDataSource Gridview Insert Fails W/ Empty Values Dictionary
body: <p>I have a gridview to which I have created an Insert Template in the footer row.</p>
  
  <p>I have an ObjectDataSource which is bound to a business object.</p>
  
  <p>I have an OnInserting event handler which never gets fired.</p>
  
  <p>The program encounters an error once I call .Insert on the ObjectDataSource.  The error I receive is that there are no values and that I should check to make sure the values dictionary is not empty.</p>
  
  <p>I do not see a way to insert with a dictionary as a parameter.  I have seen mention of grabbing the ObjectDataSourceView and using it's Insert method but I do not see any mention of how to do that and MSDN claims you do not have access.</p>
  
  <p>Is reflection the way to go here?  Is there a better way of having an insert row on a gridview? Am I missing something obvious in my steps here?</p>
  
  <p>Below is the code:<br/>
  ObjectDataSource:</p>
  
  <pre><code>    &lt;asp:ObjectDataSource ID="LeasesDS" runat="server" OnInserting="LeasesDS_Inserting" 
      DataObjectTypeName="CLS.BusObjects.LeaseObj" DeleteMethod="Delete" 
      InsertMethod="Insert" OldValuesParameterFormatString="original_{0}" 
      SelectMethod="GetLeasesByCustomerID" TypeName="CLS.BusObjects.LeaseObj" 
      UpdateMethod="Update"&gt;
      &lt;SelectParameters&gt;
          &lt;asp:Parameter Name="customerID" Type="Int32" /&gt;
      &lt;/SelectParameters&gt;
      &lt;InsertParameters&gt;
          &lt;asp:Parameter Name="CustomerID" Type="Int32" /&gt;
          &lt;asp:Parameter Name="PurchaseDate" Type="DateTime" /&gt;
          &lt;asp:Parameter Name="AutoYear" Type="Int32" /&gt;
          &lt;asp:Parameter Name="Make" Type="String" /&gt;
          &lt;asp:Parameter Name="Model" Type="String" /&gt;
          &lt;asp:Parameter Name="LeaseEndDate" Type="DateTime" /&gt;
      &lt;/InsertParameters&gt;
  &lt;/asp:ObjectDataSource&gt;
  </code></pre>
  
  <p><br/>
  CodeBehind Methods:</p>
  
  <pre><code>protected void LeasesGrid_RowCommand(object sender, GridViewCommandEventArgs e)
      {
          if (e.CommandName == "Insert" &amp;&amp; Page.IsValid)
          {
              LeasesDS.Insert();
          }
      }
      protected void LeasesDS_Inserting(object sender, ObjectDataSourceMethodEventArgs e)
      {
          DropDownList GridCustomersList = (DropDownList)LeasesGrid.FooterRow.FindControl("GridCustomersList");
          TextBox PurchaseDate = (TextBox)LeasesGrid.FooterRow.FindControl("PurchaseDate");
          TextBox AutoYear = (TextBox)LeasesGrid.FooterRow.FindControl("AutoYear");
          TextBox Make = (TextBox)LeasesGrid.FooterRow.FindControl("Make");
          TextBox Model = (TextBox)LeasesGrid.FooterRow.FindControl("Model");
          TextBox LeaseEndDate = (TextBox)LeasesGrid.FooterRow.FindControl("LeaseEndDate");
          e.InputParameters["CustomerID"] = Convert.ToInt32(GridCustomersList.SelectedValue);
          DateTime? purchaseDate = null;
          if (!string.IsNullOrEmpty(PurchaseDate.Text)) purchaseDate = Convert.ToDateTime(PurchaseDate.Text);
          e.InputParameters["PurchaseDate"] = purchaseDate;
          int? autoYear = null;
          if (!string.IsNullOrEmpty(AutoYear.Text)) autoYear = Convert.ToInt32(AutoYear.Text);
          e.InputParameters["AutoYear"] = autoYear;
          string make = null;
          if (!string.IsNullOrEmpty(Make.Text)) make = Make.Text;
          e.InputParameters["Make"] = make;
          string model = null;
          if (!string.IsNullOrEmpty(Model.Text)) model = Model.Text;
          e.InputParameters["Model"] = model;
          DateTime? leaseEndDate = null;
          if (!string.IsNullOrEmpty(LeaseEndDate.Text)) leaseEndDate = Convert.ToDateTime(LeaseEndDate.Text);
          e.InputParameters["LeaseEndDate"] = leaseEndDate;
      }
  </code></pre>