A web page is about to show a data. This data may generate from database or other object like an class instance.
Mostly, data is presented to a table and a lot of tutorial about making a table that I have is related to database. Developers have a listview / gridview / repeater etc for data view and sqldatasource control as a data source.
Although sqldatasource is good and may increase productivity. An organisation is not always use SQL Server and one of their web tables may not use database at all.
So I prefer to use ObjectDataSource control. This control is more generic data source because we use our own bare class to return a DataTable instance. Since we write our own class then inside it we can code an operation to any RDBMS or work with any objects.
ObjectDataSource control is also good option to retrieve data via Web Service from another Server and maybe that Server is located at different site. We cant see any code like database connection in Web Service but only class and namespace reference of it. Although maybe there is a database operation inside Web Service itself.
In this blog post, I generate the data manualy to DataTable in the first example and secondly, I generate it from webservice and database. Both of them show data via listview and use arbitrary class that I make. ObjectDatasource acts as bridge between this custom class instance and listview.
Adding Data Manualy to DataTable
Here’s the example:
I will show simple table that has persons info with their name, city and province.
.aspx file (piece of code):
<div> <table> <thead> <tr> <th>Name</th> <th>City</th> <th>Province</th> </tr> </thead> </table> <tr> <td></td><td></td> <td></td> </tr> </div>