Deleting Data From Gridview Using Objectdatasource Control - Part 15
Deleting Data From Gridview Using Objectdatasource Control - Part 15
net and c# video tutorial: Deleting data from gridview using objectdatasource control - Part 15
Support us .Net Basics C# SQL ASP.NET ADO.NET MVC Slides C# Programs Subscribe Buy DVD
Suggested Videos
Part 12 - Using stored procedures with objectdatasource control
Part 13 - Deleting data from gridview using sqldatasource control
Part 14 - ConflictDetection property of SqlDataSource control
Best software training and placements in
marathahalli, bangalore. For further
details please call 09945699393.
We will be using tblEmployee table for this demo. For SQL script to create and
CBSE Class 9 Maths
populate this table, please refer to, Part 13 - Deleting data from gridview using
Number Systems
sqldatasource control of asp.net gridview tutorial.
CPT Tutorial
Part 1 : Video | Text | Slides
Important Videos
The Gift of Education
Steps to delete from gridview using objectdatasource control the following are Dot Net Video Tutorials
the steps
Angular 2 Tutorial
1. Create EmployeeDataAccessLayer class
2. Create Employee business object in EmployeeDataAccessLayer.cs file Design Patterns
3. Add a static method to select all employees in EmployeeDataAccessLayer class
4. Add a static method to delete employee record using EmployeeId, in ASP.NET Web API
EmployeeDataAccessLayer class
5. Configure objectdatasource and gridview control. Bootstrap
6. Set "EmployeeId" as the value for DataKeyNames property of the gridview control.
AngularJS Tutorial
Now let us look at the steps in detail
jQuery Tutorial
Step 1: Create EmployeeDataAccessLayer class
Right click on the web application project and add a class file with name JavaScript with ASP.NET Tutorial
EmployeeDataAccessLayer.cs
JavaScript Tutorial
Step 2: Create Employee business object in EmployeeDataAccessLayer.cs file
public class Employee Charts Tutorial
{
LINQ
public int EmployeeId { get; set; }
public string Name { get; set; }
LINQ to SQL
public string Gender { get; set; }
public string City { get; set; } LINQ to XML
}
Entity Framework
Step 3: Add a static method to select all employees in EmployeeDataAccessLayer
http://csharp-video-tutorials.blogspot.in/2013/03/deleting-data-from-gridview-using.html 1/5
8/28/2017 Sql server, .net and c# video tutorial: Deleting data from gridview using objectdatasource control - Part 15
class WCF
public static List<Employee> GetAllEmployees()
{ ASP.NET Web Services
List<Employee> listEmployees = new List<Employee>();
Dot Net Basics
string CS = ConfigurationManager.ConnectionStrings["DBCS"].ConnectionString; C#
using (SqlConnection con = new SqlConnection(CS))
{ SQL Server
SqlCommand cmd = new SqlCommand("Select * from tblEmployee", con);
con.Open(); ADO.NET
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read()) ASP.NET
{
GridView
Employee employee = new Employee();
employee.EmployeeId = Convert.ToInt32(rdr["EmployeeId"]); ASP.NET MVC
employee.Name = rdr["Name"].ToString();
employee.Gender = rdr["Gender"].ToString(); Visual Studio Tips and Tricks
employee.City = rdr["City"].ToString();
Dot Net Interview Questions
listEmployees.Add(employee);
} Slides
}
Entity Framework
Step 6: Set "EmployeeId" as the value for DataKeyNames property of the gridview Written Test
control.
This can be done in HTML or code. Since, EmployeeId is the primary key, we need to
set it as the value for "DataKeyNames" property of the gridview control, otherwise
deleting does not work.
http://csharp-video-tutorials.blogspot.in/2013/03/deleting-data-from-gridview-using.html 2/5