GridView insert update delete in asp.net using objectdatasource – Part 2404:33

  • 0
Published on July 1, 2017

Link for csharp, asp.net, ado.net, dotnet basics and sql server video tutorial playlists

Link for text version of this video

In this video we will discuss about performing an insert, update and delete on asp.net gridview control using objectdatasource. Please watch Part 23 of asp.net gridview tutorial, before proceeding. In Part 23, we discussed about doing exactly the same thing using sqldatasource control. So we will be modifying the same example to use objectdatasource control instead of sqldatasource control.

Add a class file with name EmployeeDataAccessLayer.cs to your project. Create methods to select, insert, update and delete. Please refer to the following link for these methods

1. Compile your project.
2. On WebForm1.aspx delete “SqlDataSource1” control.
3. Drag and drop ObjectDataSource control onto the webform.
4. Now configure ObjectDataSource control to use
GetAllEmployees() as “Select” Method
DeleteEmployee(int EmployeeId) as “Delete” method
UpdateEmployee(int EmployeeId, string Name, string Gender, string City) as “Update” method
InsertEmployee(string Name, string Gender, string City) as “Insert” method

Now change DataSourceID property of GridView1 control from “SqlDataSource1” to “ObjectDataSource1” and Save. You will get a message asking, if you want to “Refresh Fields and Keys for GridView1. Click No.

Finally in code-behind file change the implementation of “lbInsert_Click” as shown below.
protected void lbInsert_Click(object sender, EventArgs e)
{
ObjectDataSource1.InsertParameters[“Name”].DefaultValue =
((TextBox)GridView1.FooterRow.FindControl(“txtName”)).Text;
ObjectDataSource1.InsertParameters[“Gender”].DefaultValue =
((DropDownList)GridView1.FooterRow.FindControl(“ddlInsertGender”)).SelectedValue;
ObjectDataSource1.InsertParameters[“City”].DefaultValue =
((TextBox)GridView1.FooterRow.FindControl(“txtCity”)).Text;
ObjectDataSource1.Insert();
}

https://cafeadobro.ro/

https://www.stagebox.uk/wp-includes/depo10-bonus10/

depo 25 bonus 25

https://parfumschristianblanc.com/

https://www.barplate.com/wp-includes/js/qris/

https://hotmusic507.org/

Enjoyed this video?
"No Thanks. Please Close This Box!"