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

  • SEARCH
  • Home
  • 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 1093341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T23:48:45+00:00 2026-05-16T23:48:45+00:00

Enviroment: asp.net framework 2.0 I’m having problems with the Delete method of and ObjectDataSource

  • 0

Enviroment: asp.net framework 2.0

I’m having problems with the Delete method of and ObjectDataSource on a custom object. The Select, Insert and Update methods works fine.

Here is the code of the classes:

public class Car
{
    public string ID {get; set;}//I know this is 3.0+ syntax.
    public string Description {get; set;}//I know this is 3.0+ syntax.

    public bool Equals(Car other)
    {
        if (ReferenceEquals(null, other)) return false;
        if (ReferenceEquals(this, other)) return true;
        return other.ID == ID;
    }

    public override bool Equals(object obj)
    {
        if (ReferenceEquals(null, obj)) return false;
        if (ReferenceEquals(this, obj)) return true;
        return obj.GetType() == typeof (Car) && Equals((Car) obj);
    }

    public override int GetHashCode()
    {
        return ID;
    }
}

public class CarList
{
    private static List<Car> _cars;

    public CarList()
    {
        if(_cars == null) 
            _cars = new List<Car>();

        //Create some cars and insert them here...
    }

    public List<Car> Select()
    {
        return _cars;
    }

    public void Update(Car updatedCar)
    {
        int i = _cars.IndexOf(updatedCar);
        if(i != -1)
        {
            _cars[i] = updatedCar;
        }
    }

    public void Insert(Car insertedCar)
    {
        _cars.Add(insertedCar);
    }

    public void Delete(Car deletedCar)
    {
        _cars.Remove(deletedCar);
    }
}

And this is the code for the ObjectDataSource and the DetailsView:

<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
    DataObjectTypeName="Car"
    TypeName="CarList"
    DeleteMethod="Delete" 
    InsertMethod="Update" 
    SelectMethod="Select" 
    UpdateMethod="Update">
</asp:ObjectDataSource>

<asp:DetailsView ID="DetailsView1" runat="server" AllowPaging="True" AutoGenerateRows="False"
    CellPadding="4" DataSourceID="ObjectDataSource1" ForeColor="#333333" GridLines="None"
    Height="50px" Width="125px">
    <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <CommandRowStyle BackColor="#D1DDF1" Font-Bold="True" />
    <RowStyle BackColor="#EFF3FB" />
    <FieldHeaderStyle BackColor="#DEE8F5" Font-Bold="True" />
    <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
    <Fields>
        <asp:BoundField DataField="Id" HeaderText="Id" />
        <asp:BoundField DataField="Description" HeaderText="Model" />
        <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />
    </Fields>
    <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
    <EditRowStyle BackColor="#2461BF" />
    <AlternatingRowStyle BackColor="White" />
</asp:DetailsView>

When I try to delete an Item and do a Debug to the method Delete, it has the parameter deletedCar like this:

ID=0
Description=null

But when I do a Debug to the Update or Insert Methods the Car object is correctly populated with the correct data.

What is going on?

  • 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. Editorial Team
    Editorial Team
    2026-05-16T23:48:45+00:00Added an answer on May 16, 2026 at 11:48 pm

    Set DataKeyNames (The primary key property) in DetailsView.

    <asp:DetailsView DataKeyNames="ID" />
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use: SELECT p.id as a, p.url as b, t.id as… May 17, 2026 at 3:22 am
  • Editorial Team
    Editorial Team added an answer There are two parts to the problem First Issue You… May 17, 2026 at 3:19 am
  • Editorial Team
    Editorial Team added an answer I thought I'd show the regex approach, too. It doesn't… May 17, 2026 at 3:18 am

Trending Tags

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

Top Members

Related Questions

We primarily use an ASP.NET environment at work. Right now I'm building an application
What are differences between CallContext and ThreadStatic? I've understood that in an ASP.NET environment
I use ASP.NET and WCF services in a load balanced web server environment, using
Environment: Windows 2003 Server (32 bit); IIS6, ASP.NET 2.0 (3.5); 4Gb Ram; 1 Worker
If you were an asynchronous javascript call in an Asp.Net MVC environment, and you
Environment: Windows Server 2003 R2 Enterprise 64bit, SP2 .NET framework is supposedly installed (2.0
I have a ASP.NET application running on a remote web server and I just
I assume that the basic setup for ASP.net web development today is: Windows Vista
What is the best way to get hosting of an ASP.NET MVC application to
I need my ASP.NET web application to use silverlight controls in my web page.

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.