Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 99991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:29:38+00:00 2026-05-11T00:29:38+00:00

I have a gridview to which I have created an Insert Template in the

  • 0

I have a gridview to which I have created an Insert Template in the footer row.

I have an ObjectDataSource which is bound to a business object.

I have an OnInserting event handler which never gets fired.

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.

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.

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?

Below is the code:
ObjectDataSource:

    <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'>     <SelectParameters>         <asp:Parameter Name='customerID' Type='Int32' />     </SelectParameters>     <InsertParameters>         <asp:Parameter Name='CustomerID' Type='Int32' />         <asp:Parameter Name='PurchaseDate' Type='DateTime' />         <asp:Parameter Name='AutoYear' Type='Int32' />         <asp:Parameter Name='Make' Type='String' />         <asp:Parameter Name='Model' Type='String' />         <asp:Parameter Name='LeaseEndDate' Type='DateTime' />     </InsertParameters> </asp:ObjectDataSource> 

CodeBehind Methods:

protected void LeasesGrid_RowCommand(object sender, GridViewCommandEventArgs e)     {         if (e.CommandName == 'Insert' && 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;     } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T00:29:38+00:00Added an answer on May 11, 2026 at 12:29 am

    Your example isn’t consistent since you have DataObjectTypeName set, but your LeasesDS_Inserting method is adding parameters as if it’s not.

    If you don’t need DataObjectTypeName, you can remove it and then you should have a better chance getting this to work.

    If you need DataObjectTypeName or just prefer it (as I do), there is a way to get this to work, but it’s not pretty.

    In your LeasesGrid_RowCommand method, you can use code like this to get the view:

    IDataSource ds = (IDataSource)LeasesDS; DataSourceView view = ds.GetView(LeasesGrid.DataMember); 

    After getting the view, you can build a dictionary containing the values that need to get written to the data object that will eventually get passed in to your Insert method. The code for that will look very similar to what you have in LeasesDS_Inserting, but you’ll be inserting into your own dictionary instead of e.InputParameters.

    Once you have your dictionary ready, you can invoke Insert on the view with something like this:

    view.Insert(dict, delegate { return false; }); 

    That should do it.

    You won’t need the LeasesDS_Inserting method any more since the view’s Insert method will do the work of converting the dictionary you gave it into the data object that it’s going to pass in to your Insert method.

    If you need to do more processing of the properties on that data object, you will see it in the InputParameters dictionary passed in to LeasesDS_Inserting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Are you running on OS 3.0? I saw the same… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer It looks like you need to register Apache::Session::Memcached with Apache::Session::Wrapper,… May 12, 2026 at 1:19 am
  • Editorial Team
    Editorial Team added an answer Use DATENAME or DATEPART: SELECT DATENAME(dw,GETDATE()) -- Friday SELECT DATEPART(dw,GETDATE())… May 12, 2026 at 1:19 am

Related Questions

I have written some code to do a bulk update of a gridview. In
I have a Gridview, which is bound to an IList. I'd like to have
I have an ASP.NET GridView which has columns that look like this: | Foo
I have an extended GridView class, GridViewEx, which inherits from the basic ASP.NET gridview.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.