Inserting updating and deleting data with the sqldatasource

I will be using the same example I used in the last article to add those new operations. Your result maybe different from mine if you have made changes to the Northwind database.Before I start I want tell you that there are better ways of working with data in ASP. I myself make a lot of changes to this database, especially if I’m writing an article, so don’t worry about it as long as it’s working as it should be.NET code by hand first, especially if you are a beginner. Note how the List Box control selects the last item only when you INSERT or DELETE a record, but when the page is first loaded it’s set to the first item on the list. Let’s discuss the main functionality of our page, namely the INSERT and DELETE operations, which have been written in the Insert New Employee() and Delete Employee() methods. After we create the parameter we must add it to the Sql Command.

inserting updating and deleting data with the sqldatasource-5

When I click delete on a given row, it posts back but doesn't fire the delete. Have you set the Grid View's Data Key Names property?

The only difference between the tens of other gridviews and this one is that it is the child of a repeater.

Above declarations will have same result when clicking the link.

It needs to be set to the item's primary key to uniquely identify the record to modify.

If you didn't set it, clicking Delete (or Edit) would cause a postback that doesn't affect anything since a Data Key wasn't associated with each Grid View row. Data Keys property page: When the Data Key Names property is set, the Grid View control automatically creates a Data Key object for each row in the control.


Leave a Reply