Tag Archives: ObjectDataSource

How to Show Data from Any Source such as Array, DataTable, WebService and Database Using Asp.Net ListView and ObjectDataSource

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>
    

Continue reading

Optimize Large Recordset Custom Paging using ObjectDataSource, ListView, DataPager ASP .Net Controls and Row_number() SQL Server function

Introduction
Retrieve parts of recordset on web request is a very common task. Trivial method using SqlDataSource as Data Connector and GridView or List View with Data Pager Control to view recordset and its page.

Web request resulting million records will degrade performance even though developer break down onto pages. According to some experiments there is a better way than usual method to do web paging.
Please check these links http://www.4guysfromrolla.com/articles/031506-1.aspx, http://www.4guysfromrolla.com/webtech/042606-1.shtml

The best performance using record ranking method and fortunately start from SQL Server 2005 it has record ranking function Row_Number().
In earlier post about SQL Server Row_Number() function, I have explained how to code and the function’s result on sql.

To do custom paging on web, we need ObjectDataSource because it has attributes like EnablePaging, SelectMethod, SelectCountMethod, MaximumRowsParameterName, etc which are enabled us to write a code / class that handles web paging behaviour.
We can write any database operation on methods inside ObjectDataSource so that makes ObjectDataSource flexible.
Other common component on ASP .Net like SqlDataSource is only work for SQL Server and does not has default custom paging capabilities.
Continue reading