DataSource controls were introduced in ASP 2.0. These are the controls that can be bound to external data sources such as Databases, XML files, and so on. We can find these controls under Data tab in toolbox in ASP.Net (Sql DataSource, Linq DataSource, Object DataSource).
They can be used to connect to and retreive data from various types of data sources without the need to write code to perform such operations.
Entity DataSource is a new DataSource for ASP.NET 3.5 like other controls which makes binding ASP.NET UI controls to Entity Data Models very easy. This can be used in data binding scenario. This helps to create data driven applications quickly and easy and to perform CRUD (Create, Update, Delete) operations on data based in an Entity Data Model.
The code gets minimized and we can easily develop the code for our application.
While using Entity Data Model, the table we use should definitly contain a primary key constraint otherwise we cannot access the table using Entity Data Model.
Open VisualStudio 2008 or 2010 and add a Web Application and name it.
Open Toolbox, under Data controls tab drag and drop a GridView control and Entity DataSource onto Default.aspx page.
Right click on Solution Explorer, select Add, under that select Add new item.
Then click on Data, and under that select Entity ADO.NET Model.
Now, under Choose Model Contents select Generate from Database and click Next.
Choose your Data Connection and click Next.
By default it saves connection string in configuration file.
Then, under tables, select your table and click next.
Now, your dataobject appears as below.
Now, click on Design, and click on the arrow of the entity datasource to configure the Entity DataSource control.
Build the solution.
Then configure ObjectContext and click next.
Configure DataSelection and click next.
Now, click on the arrow of the GridView to configure.
Choose you data source id for GridView Data Source. You can enable Sorting, Deleting, Selection, Editing, Paging.
Click on Source and you can find the total code.
Now run the solution and grid appears on the web page.
Shree. Prabu_Spark, if this helps please login to Mark As Answer. | Alert Moderator